Skip to content

Commit 60d7781

Browse files
committed
Add patman test
1 parent b71e262 commit 60d7781

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

tests/explicit-nulls/neg-patmat/patmat1.scala renamed to tests/explicit-nulls/neg-patmat/match-pat.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
class Foo {
2+
23
val s: String = ???
3-
s match {
4-
case s: String => 100 // warning: type test will always succeed
5-
case _ => 200 // error: unreachable
6-
}
74

85
s match {
9-
case s: String => 100 // warning: type test will always succeed
6+
case s: String => 100
107
case _ => 200 // error: unreachable
118
}
129

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

1714
val a: Animal = ???
15+
1816
a match {
1917
case Dog(name) => 100
2018
case Cat => 200
2119
case _ => 300 // error: unreachable
2220
}
2321

24-
val a2: Animal|Null = ???
22+
val a2: Animal | Null = ???
23+
2524
a2 match {
2625
case Dog(_) => 100
2726
case Cat => 200
2827
case _ => 300
2928
}
3029

31-
val a3: Animal|Null = ???
30+
val a3: Animal | Null = ???
31+
3232
a3 match {
3333
case Dog(_) => 100
3434
case Cat => 200
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.language.unsafeNulls
2+
3+
def test1 =
4+
val s: String = ???
5+
s match
6+
case _: String =>
7+
// under unsafeNulls, we should not get Match case Unreachable Warning
8+
case null => // ok
9+
10+
def test2 =
11+
val s: String | Null = ???
12+
s match
13+
case _: String =>
14+
case null =>

tests/explicit-nulls/unsafe-common/unsafe-match-null.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ def test1 =
22
val s: String = ???
33
s match
44
case _: String =>
5-
// under unsafeNulls, we should not get Match case Unreachable Warning
6-
case null => // error
5+
case null => // error: Values of types Null and String cannot be compared
76

87
def test2 =
98
val s: String | Null = ???

0 commit comments

Comments
 (0)