@jducoeur, perhaps another common exception is tuple types.
Here is a case where I WANT a match error in case I’ve forgotten a case.
object And extends BinaryOperation {
def apply():Bdd = BddTrue
def apply(bdd:Bdd):Bdd = bdd
def apply(b1: Bdd, b2: Bdd): Bdd = {
(b1, b2) match {
case (b1, b2) if b1 eq b2 => b1
case (BddTrue, _) => b2
case (BddFalse, _) => BddFalse
case (_, BddTrue) => b1
case (_, BddFalse) => BddFalse
case (b1: BddNode, b2: BddNode) => Bdd.bddOp(this, b1, b2)
}
}
}
Here is another case. By the way, in both of these cases it would be even better if the compiler would warn me about unreachable code, in case I’ve messed up in the order of the clauses.
def treeReduce[A](objs:List[A],init:A,f:(A,A)=>A):A = {
def recur(stack:List[(Int,A)],remaining:List[A]):A = {
(stack,remaining) match {
case ((a,x)::(b,y)::tail,_) if a == b => recur((a+1,f(x,y))::tail,remaining)
case (_,o::os) => recur((1,o)::stack,os)
case ((_,o)::Nil,Nil) => o
case ((_,x)::(_,y)::tail,Nil) => recur((0,f(x,y))::tail, Nil)
}
}
recur((1,init)::Nil,objs)
}