-
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.
Backport "add tracking of NotNullInfo for Match, Case, Try trees (fix #…
…21380)" to LTS (#22121) Backports #21389 to the 3.3.5. PR submitted by the release tooling. [skip ci]
- Loading branch information
Showing
4 changed files
with
117 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
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() // error // LTS specific | ||
x.replace("", "") // error | ||
|
||
def test2(i: Int) = | ||
var x: String | Null = null | ||
i match | ||
case 1 => x = "1" | ||
case _ => x = " " | ||
x.replace("", "") // error // LTS specific | ||
|
||
def test3(i: Int) = | ||
var x: String | Null = null | ||
i match | ||
case 1 if x != null => () | ||
case _ => x = " " | ||
x.trim() // error // LTS specific |
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(" ", "") // error // LTS specific | ||
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 // error // LTS specific | ||
|
||
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 |