Skip to content

Type bound lost in pattern matching  #20040

Open
@Krever

Description

@Krever

Compiler version

3.3.3, 3.4.0, 3.4.1-RC2

Minimized code

sealed trait Foo[A]
final case class Bar[A, B <: A]() extends Foo[A]

/*
def getB[A](f: Foo[A]): Unit = f match {
  case bar: Bar[A, b] =>
    println(summon[b <:< A])
}
*/

def getB[A](f: Foo[A]): Unit = f match {
  case bar1: Bar[A, ? <: A] => bar1 match {
    case bar2: Bar[A, b] =>
      println(summon[b <:< A])
  }
}

Output

If we uncomment faulty implementation, the compiler outputs:

Cannot prove that b <:< A.

Expectation

I believe the both variants are equivalent and should work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions