Hi,
naively when I do a pattern matching for a type X on a val of the type Y, I’d expect that the compiler would understand that the resulting type is Y with X. This also works nicely when I work with specific types, but when I work with type parameters, I cannot get the compiler to compile without warning.
Here a short sample:
trait T1
trait T2
def testMatch0(a: T1) = {
def doIt(x: T1 with T2) = ???
a match {
case b: T2 => doIt(b) // no problem here
}
}
def testMatchError[A <: T1](a: A) = {
def doIt(x: A with T2) = ???
a match {
case b: T2 => doIt(b) // error, required type is A with T2, but found is T1 with T2, even though a is of type A
}
}
def testMatchWarning[A <: T1](a: A) = {
def doIt(x: A with T2) = ???
a match {
case b: A with T2 => doIt(b) // warning, since the type A will be eliminated by erasure
}
}
Do you know any workaround, how to make my code warning free?