forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NotNullInfo for Case and Try; add more tests
- Loading branch information
Showing
3 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
@main def test() = { | ||
def test1 = | ||
var x: String | Null = null | ||
x = "" | ||
1 match { | ||
1 match | ||
case 1 => x = null | ||
} | ||
case _ => x = x.trim() // ok | ||
x.replace("", "") // error | ||
} | ||
|
||
def test2(i: Int) = | ||
var x: String | Null = null | ||
i match | ||
case 1 => x = "1" | ||
case _ => x = " " | ||
x.replace("", "") // ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def test1(i: Int): Int = | ||
var x: String | Null = null | ||
if i == 0 then x = "" | ||
else x = "" | ||
try | ||
x = x.replace(" ", "") // ok | ||
throw new Exception() | ||
catch | ||
case e: Exception => | ||
x = x.replaceAll(" ", "") // error | ||
x = null | ||
x.length // error | ||
|
||
def test2: Int = | ||
var x: String | Null = null | ||
try throw new Exception() | ||
finally x = "" | ||
x.length // ok | ||
|
||
def test3 = | ||
var x: String | Null = "" | ||
try throw new Exception() | ||
catch case e: Exception => | ||
x = (??? : String | Null) | ||
finally | ||
val l = x.length // error | ||
|
||
def test4: Int = | ||
var x: String | Null = null | ||
try throw new Exception() | ||
catch | ||
case npe: NullPointerException => x = "" | ||
case _ => x = "" | ||
x.length // ok |