Open
Description
I'm trying this example in scala 2.12.8
class B[N<:B[N]] { def foo(x:N) = println(s"$x") }
class A extends B[A]
def bar[N<:B[N]](n:N, v:A) = { n match { case n:A => n.foo(v); case _ => } }
The above example gives folllowing error
error: type mismatch;
found : this.A
required: _1
def bar[N<:B[N]](n:N, v:A) = { n match { case n:A => n.foo(v); case _ => } }
^
However, this compiles
def bar[N<:B[N]](n:N, v:A) = { n match { case n:A => n.asInstanceOf[A].foo(v); case _ => } }
Why does not n
have type A after matched to A. This only occurs when N in B has bound N<:B[N]
.