Skip to content

Commit

Permalink
Add patman test
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Nov 19, 2021
1 parent 08bae24 commit f83a846
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class Foo {

val s: String = ???
s match {
case s: String => 100 // warning: type test will always succeed
case _ => 200 // error: unreachable
}

s match {
case s: String => 100 // warning: type test will always succeed
case s: String => 100
case _ => 200 // error: unreachable
}

Expand All @@ -15,20 +12,23 @@ class Foo {
case object Cat extends Animal

val a: Animal = ???

a match {
case Dog(name) => 100
case Cat => 200
case _ => 300 // error: unreachable
}

val a2: Animal|Null = ???
val a2: Animal | Null = ???

a2 match {
case Dog(_) => 100
case Cat => 200
case _ => 300
}

val a3: Animal|Null = ???
val a3: Animal | Null = ???

a3 match {
case Dog(_) => 100
case Cat => 200
Expand Down
14 changes: 14 additions & 0 deletions tests/explicit-nulls/neg-patmat/unsafe-match-null-pat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.language.unsafeNulls

def test1 =
val s: String = ???
s match
case _: String =>
// under unsafeNulls, we should not get Match case Unreachable Warning
case null => // ok

def test2 =
val s: String | Null = ???
s match
case _: String =>
case null =>
3 changes: 1 addition & 2 deletions tests/explicit-nulls/unsafe-common/unsafe-match-null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ def test1 =
val s: String = ???
s match
case _: String =>
// under unsafeNulls, we should not get Match case Unreachable Warning
case null => // error
case null => // error: Values of types Null and String cannot be compared

def test2 =
val s: String | Null = ???
Expand Down

0 comments on commit f83a846

Please sign in to comment.