bug
bug copied to clipboard
Exhaustive pattern matching is found non-exhaustive for anonymous class
The following two snippets must live in different files.
First a sealed Base hierarchy.
sealed abstract class Base
sealed trait A extends Base
object A {
case object Root extends Base
def apply(param: String): A = {
new A {}
}
}
Then trying to pattern match:
object ExhaustiveMatchWarning {
def test() = {
val b: Base = A("blabla")
b match {
case A.Root => println("Root")
case path: A => println("Not root")
}
}
}
produces a warning
[warn] [...]/ExhaustiveMatchWarning.scala:5: match may not be exhaustive.
[warn] It would fail on the following input: (_ : this.<local child>)
[warn] b match {
[warn] ^
[warn] one warning found
Imported From: https://issues.scala-lang.org/browse/SI-9677?orig=1 Reporter: Bruno Bieth (mustaghattack) Affected Versions: 2.11.7, 2.11.8
behavior in 2.13.16 is unchanged
in Scala 3.6.3,
% /usr/local/scala/scala3-3.6.3/bin/scalac -classpath . Test.scala
-- [E029] Pattern Match Exhaustivity Warning: Test.scala:5:4 -------------------
5 | b match {
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Base (anonymous)
|
| longer explanation available when compiling with `-explain`
1 warning found