File tree 2 files changed +28
-7
lines changed
2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
- // Test flow-typing when NotNullInfos are from non-null cases
1
+ // Test flow-typing when NotNullInfos are from cases
2
2
3
3
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
10
14
}
11
15
}
You can’t perform that action at this time.
0 commit comments