scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Exhaustivity counter-examples misleading with custom extractors #12713

Closed lrytz closed 1 year ago

lrytz commented 1 year ago
sealed trait A
case object A1 extends A
case object A2 extends A
sealed trait T { def a: A }
object T { def unapply(t: T): Some[A] = Some(t.a) }
case class T1(x: Int) extends T { def a = A1 }
case class T2(x: Int) extends T { def a = A2 }

object Test {
  def m(t: T) = t match {
    case T(A1) => 0
    // case T(A2) => 1
  }
}

Exhaustivity can correctly identify the (in)completeness of the match, but the counter-examples in the warning message are misleading.

➜ sandbox sc Test.scala
Test.scala:10: warning: match may not be exhaustive.
It would fail on the following inputs: T1(_), T2(_)
  def m(t: T) = t match {
                ^
1 warning
lrytz commented 1 year ago

Duplicate of https://github.com/scala/bug/issues/12567, adding the example there.