Skip to content

Commit

Permalink
Put i13864 in the blacklist of best-effort test.
Browse files Browse the repository at this point in the history
[Cherry-picked fe0bdad][modified]
  • Loading branch information
WojciechMazur committed Dec 3, 2024
1 parent d2c9b3f commit fdbae42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2048,14 +2048,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
untpd.Block(makeCanThrow(capabilityProof), expr)

def typedTry(tree: untpd.Try, pt: Type)(using Context): Try = {
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
// uses the types of patterns in `tree.cases` to determine the capabilities.
// Hence, we create a copy of cases with empty body and type check that first, then type check
// the rest of the tree in order.
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef(_)(body = EmptyTree))
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree, defn.ThrowableType, WildcardType)

val expr2 :: cases2x = harmonic(harmonize, pt) {
// We want to type check tree.expr first to comput NotNullInfo, but `addCanThrowCapabilities`
// uses the types of patterns in `tree.cases` to determine the capabilities.
// Hence, we create a copy of cases with empty body and type check that first, then type check
// the rest of the tree in order.
// It may seem that invalid references can be created if the type of the pattern contains
// type binds, but this is not a valid `CanThrow` capability (checked by `addCanThrowCapabilities`),
// so it is not a problem.
val casesEmptyBody1 = tree.cases.mapconserve(cpy.CaseDef(_)(body = EmptyTree))
val casesEmptyBody2 = typedCases(casesEmptyBody1, EmptyTree, defn.ThrowableType, WildcardType)
val expr1 = typed(addCanThrowCapabilities(tree.expr, casesEmptyBody2), pt.dropIfProto)
val casesCtx = ctx.addNotNullInfo(expr1.notNullInfo.retractedInfo)
val cases1 = typedCases(tree.cases, EmptyTree, defn.ThrowableType, pt.dropIfProto)(using casesCtx)
Expand Down
6 changes: 3 additions & 3 deletions tests/explicit-nulls/neg/i21380b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ def test1 =
x = ""
1 match
case 1 => x = null
case _ => x = x.trim() // ok
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("", "") // ok
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() // ok
x.trim() // error // LTS specific
4 changes: 2 additions & 2 deletions tests/explicit-nulls/neg/i21380c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def test1(i: Int): Int =
if i == 0 then x = ""
else x = ""
try
x = x.replace(" ", "") // ok
x = x.replace(" ", "") // error // LTS specific
throw new Exception()
catch
case e: Exception =>
Expand All @@ -15,7 +15,7 @@ def test2: Int =
var x: String | Null = null
try throw new Exception()
finally x = ""
x.length // ok
x.length // error // LTS specific

def test3 =
var x: String | Null = ""
Expand Down

0 comments on commit fdbae42

Please sign in to comment.