dotty icon indicating copy to clipboard operation
dotty copied to clipboard

Inaccurate warning in pattern matcher

Open abeln opened this issue 6 years ago • 0 comments

  1 class Foo {
  2   val s: String = ???
  3   s match {
  4     case x: String => 1
  5     // Test that this isn't marked as unreachable (because pattern matching) type tests
  6     // use isInstanceOf and null.isInstanceOf[T] returns false for all T.
  7     case null => 2
  8   }
  9 }
-- [E122] Syntax Warning: tests/pos/explicit-null-pattern-matching2.scala:4:9 --
4 |    case x: String => 1
  |         ^^^^^^^^^
  |The highlighted type test will always succeed since the scrutinee type (class String) is t

This is inaccurate because case x: String won't match null.

Possibly (probably) an upstream bug.

abeln avatar Feb 19 '19 19:02 abeln