Skip to content

Commit 0e1f277

Browse files
committed
Add test for i11967
1 parent 775d881 commit 0e1f277

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test flow-typing when NotNullInfos are from cases
2+
3+
object MatchTest {
4+
5+
def stringOrNullToString(s: String | Null): String = s match {
6+
case null => "null"
7+
// after the null case, s becomes non-nullable
8+
case _ => s
9+
}
10+
11+
def stringOrNullToString2(s: String | Null): String = s match {
12+
case null => "null"
13+
// s in the case is new variable different from the paramter s
14+
// it has the original type: String | Null
15+
case s => s // error
16+
}
17+
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
// Test flow-typing when NotNullInfos are from non-null cases
1+
// Test flow-typing when NotNullInfos are from cases
22

33
object MatchTest {
4-
locally {
5-
val s: String|Null = ???
6-
s match {
7-
case _: String => println(s.length)
8-
case _ => println(0)
9-
}
4+
5+
def lengthOfStringOrNull(s: String | Null): Int = s match {
6+
case _: String => s.length
7+
case _ => 0
8+
}
9+
10+
def stringOrNullToString(s: String | Null): String = s match {
11+
case null => "null"
12+
// after the null case, s becomes non-nullable
13+
case _ => s
1014
}
1115
}

0 commit comments

Comments
 (0)