Skip to content

Pattern match not return matched F-bounded type  #11375

Open
@yaqiz01

Description

@yaqiz01

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].

Metadata

Metadata

Assignees

No one assigned

    Labels

    f-boundsfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)patmat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions