Open som-snytt opened 3 years ago
$ scala -Vprint:_ $(f 'object X; object Y; object Test extends App { println(X match { case _: Y.type => 1 case _ => 2 }) }')
[[syntax trees at end of patmat]] // scala-test.zaWc1LcN.scala
...
scala.Predef.println({
case <synthetic> val x1: X.type = X;
case5(){
if (x1.isInstanceOf[X.type with Y.type])
matchEnd4(1)
else
case6()
};
case6(){
matchEnd4(2)
};
matchEnd4(x: Any){
x
}
})
[[syntax trees at end of erasure]] // scala-test.zaWc1LcN.scala
...
scala.Predef.println({
case <synthetic> val x1: X.type = X;
case5(){
if (X.eq(x1))
matchEnd4(scala.Int.box(1))
else
case6()
};
case6(){
matchEnd4(scala.Int.box(2))
};
matchEnd4(x: Object){
x
}
})
o_O
No longer crashes REPL (by 2.13.6) but still a bad match.
Dotty warns:
scala> X match { case _: Y.type => 1 case _ => 2 }
1 warning found
-- [E030] Match case Unreachable Warning: ------------------------------------------------------------------------------
1 |X match { case _: Y.type => 1 case _ => 2 }
| ^^^^^^^^^
| Unreachable case
val res0: Int = 2
reproduction steps
or
problem
I expect the other answer (because
X ne Y
) and not a crash.