Skip to content

Commit fdbae42

Browse files
committed
Put i13864 in the blacklist of best-effort test.
[Cherry-picked fe0bdad][modified]
1 parent d2c9b3f commit fdbae42

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,14 +2048,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20482048
untpd.Block(makeCanThrow(capabilityProof), expr)
20492049

20502050
def typedTry(tree: untpd.Try, pt: Type)(using Context): Try = {
2051-
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2052-
// uses the types of patterns in `tree.cases` to determine the capabilities.
2053-
// Hence, we create a copy of cases with empty body and type check that first, then type check
2054-
// the rest of the tree in order.
2055-
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef(_)(body = EmptyTree))
2056-
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree, defn.ThrowableType, WildcardType)
2057-
20582051
val expr2 :: cases2x = harmonic(harmonize, pt) {
2052+
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
2053+
// uses the types of patterns in `tree.cases` to determine the capabilities.
2054+
// Hence, we create a copy of cases with empty body and type check that first, then type check
2055+
// the rest of the tree in order.
2056+
// It may seem that invalid references can be created if the type of the pattern contains
2057+
// type binds, but this is not a valid `CanThrow` capability (checked by `addCanThrowCapabilities`),
2058+
// so it is not a problem.
2059+
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef(_)(body = EmptyTree))
2060+
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree, defn.ThrowableType, WildcardType)
20592061
val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
20602062
val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
20612063
val cases1 = typedCases(tree.cases, EmptyTree, defn.ThrowableType, pt.dropIfProto)(using casesCtx)

tests/explicit-nulls/neg/i21380b.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ def test1 =
33
x = ""
44
1 match
55
case 1 => x = null
6-
case _ => x = x.trim() // ok
6+
case _ => x = x.trim() // error // LTS specific
77
x.replace("", "") // error
88

99
def test2(i: Int) =
1010
var x: String | Null = null
1111
i match
1212
case 1 => x = "1"
1313
case _ => x = " "
14-
x.replace("", "") // ok
14+
x.replace("", "") // error // LTS specific
1515

1616
def test3(i: Int) =
1717
var x: String | Null = null
1818
i match
1919
case 1 if x != null => ()
2020
case _ => x = " "
21-
x.trim() // ok
21+
x.trim() // error // LTS specific

tests/explicit-nulls/neg/i21380c.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def test1(i: Int): Int =
33
if i == 0 then x = ""
44
else x = ""
55
try
6-
x = x.replace(" ", "") // ok
6+
x = x.replace(" ", "") // error // LTS specific
77
throw new Exception()
88
catch
99
case e: Exception =>
@@ -15,7 +15,7 @@ def test2: Int =
1515
var x: String | Null = null
1616
try throw new Exception()
1717
finally x = ""
18-
x.length // ok
18+
x.length // error // LTS specific
1919

2020
def test3 =
2121
var x: String | Null = ""

0 commit comments

Comments
 (0)