-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
118 additions
and
9 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
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,19 @@ | ||
@main def test() = { | ||
var x: String | Null = null | ||
if (false) { | ||
x = "" | ||
|
||
} else { | ||
x = "" | ||
} | ||
try { | ||
x = "" | ||
throw new Exception() | ||
} | ||
catch { | ||
case e: Exception => { | ||
x = null | ||
} | ||
} | ||
x.replace("", "") // error | ||
} |
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,21 @@ | ||
def test1 = | ||
var x: String | Null = null | ||
x = "" | ||
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 | ||
|
||
def test3(i: Int) = | ||
var x: String | Null = null | ||
i match | ||
case 1 if x != null => () | ||
case _ => x = " " | ||
x.trim() // 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,45 @@ | ||
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 // error | ||
// Although the catch block here is exhaustive, | ||
// it is possible that the exception is thrown and not caught. | ||
// Therefore, the code after the try block can only rely on the retracted info. | ||
|
||
def test5: Int = | ||
var x: String | Null = null | ||
try | ||
x = "" | ||
throw new Exception() | ||
catch | ||
case npe: NullPointerException => val i: Int = x.length // error |