Skip to content

Commit 74f6851

Browse files
committed
additionally include writes under try/catch/finally
1 parent f351ec4 commit 74f6851

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ object Nullables:
445445
else candidates -= name
446446
case None =>
447447
traverseChildren(tree)
448-
case _: (If | WhileDo | Typed | Match | CaseDef) =>
448+
case _: (If | WhileDo | Typed | Match | CaseDef | untpd.ParsedTry) =>
449449
traverseChildren(tree) // assignments to candidate variables are OK here ...
450450
case _ =>
451451
reachable = Set.empty // ... but not here

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

+13
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)