Skip to content

Commit df39b66

Browse files
committed
additionally include writes under try/catch/finally
1 parent d6ce1ca commit df39b66

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ object Nullables:
470470
else candidates -= name
471471
case None =>
472472
traverseChildren(tree)
473-
case _: (If | WhileDo | Typed | Match | CaseDef) =>
473+
case _: (If | WhileDo | Typed | Match | CaseDef | untpd.ParsedTry) =>
474474
traverseChildren(tree) // assignments to candidate variables are OK here ...
475475
case _ =>
476476
reachable = Set.empty // ... but not here

tests/explicit-nulls/pos/match-flow-typing.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@ def m(): String = {
66
if(x == null) "foo"
77
else x
88
}
9+
10+
def m2(): String = {
11+
var x: String|Null = "foo"
12+
try {
13+
x = x
14+
} catch {
15+
case e => x = x
16+
} finally {
17+
x = x
18+
}
19+
if(x == null) "foo"
20+
else x
21+
}

0 commit comments

Comments
 (0)