Closed
Description
Compiler version
3.2.1
from https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.2.1/scala3-compiler_3-3.2.1.jar
Minimized code
Given some generic class (in this case Wrapper
) and some other type (in this case Color
but I think this doesn't matter too much):
case class Wrapper[A](value: A)
enum Color:
case Red, Green
The following code doesn't produce any warnings I think but I expect "the type test for <blah> cannot be checked at runtime":
def test_wrong(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] =
x match
case x: Wrapper[Color.Red.type] => Some(x)
case _ => None
def test_wrong_seq(xs: Seq[Wrapper[Color]]): Seq[Wrapper[Color.Red.type]] =
xs.collect { case x: Wrapper[Color.Red.type] => x }
Output
println(test_wrong_seq(Seq(Wrapper(Color.Red), Wrapper(Color.Green))))
// outputs: List(Wrapper(Red), Wrapper(Green))
The output is expected but no warnings is not expected.
Expectation
What I expect when pattern matching on the type is:
def test_correct(x: Wrapper[Color]): Option[Wrapper[Color.Red.type]] =
x match
case x: Wrapper[Color.Red.type] => Some(x)
case x: Wrapper[Color.Green.type] => None
gives "the type test for <blah> cannot be checked at runtime":
[warn] -- [E029] Pattern Match Exhaustivity Warning: Example.scala:147:6
[warn] 147 | x match
[warn] | ^
[warn] | match may not be exhaustive.
[warn] |
[warn] | It would fail on pattern case: Wrapper(_)
[warn] |
[warn] | longer explanation available when compiling with `-explain`
[warn] -- [E030] Match case Unreachable Warning: Example.scala:152:13
[warn] 152 | case x: Wrapper[Color.Red.type] => Some(x)
[warn] | ^^^^^^^^^^^^^^^^^^^^^^^^^^
[warn] | Unreachable case
[warn] -- Unchecked Warning: Example.scala:148:13
[warn] 148 | case x: Wrapper[Color.Red.type] => Some(x)
[warn] | ^
[warn] |the type test for Wrapper[(Color.Red : => Color)] cannot be checked at runtime
[warn] -- Unchecked Warning: Example.scala:149:13
[warn] 149 | case x: Wrapper[Color.Green.type] => None
[warn] | ^
[warn] |the type test for Wrapper[(Color.Green : => Color)] cannot be checked at runtime
Hopefully this isn't a duplicate! I did some searching but I could always have missed something.