Look at this code.
trait SomeMix {
}
trait Processor[T] {
def processMix(t: T with SomeMix) = {
println("processing T with Mix")
}
def processAsUsual(t:T)= {
println("processing T")
}
def process(t:T) = {
t match {
case mix: SomeMix => processMix(mix) // <---- error here
case _ => processAsUsual(t)
}
}
}
Stupid Scala compiler shows error here:
Error:(22, 39) type mismatch; found : mix.type (with underlying type SomeMix) required: T with SomeMix case mix: SomeMix => processMix(mix)
It does not understand that expression I matching to SomeMix is already of type T. Ok lets help him. Changed code:
def process(t:T) = {
t match {
case mix: T with SomeMix => processMix(mix) // <---- warning here
case _ => processAsUsual(t)
}
}
Now it agrees that all is correct but show warning:
Warning:(22, 17) abstract type pattern T is unchecked since it is eliminated by erasure case mix: T with SomeMix => processMix(mix)
Is any good way to avoid both error and warning here?