Skip to content

Missing unchecked warning for type pattern, invariant extends contravariant #12439

@lrytz

Description

@lrytz

From scala/scala#9672 (comment)

trait C[+T]
trait D[T] extends C[T] {
  def f(x: T): T
}
class E extends D[String] {
  def f(x: String) = x.trim
}

object Test {
  def foo[T](c: C[T], t: T): Any = c match {
    case d: D[T] => d.f(t)
    case _ => 0
  }
  def main(args: Array[String]): Unit = {
    foo[Any](new E, 1)
  }
}

Doesn't give an unchecked warning in Scala 2 (fixed in Scala 3) and runs into a CCE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed 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