Skip to content

Commit

Permalink
additionally include writes under try/catch/finally
Browse files Browse the repository at this point in the history
  • Loading branch information
olhotak committed Jul 24, 2023
1 parent f351ec4 commit 74f6851
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ object Nullables:
else candidates -= name
case None =>
traverseChildren(tree)
case _: (If | WhileDo | Typed | Match | CaseDef) =>
case _: (If | WhileDo | Typed | Match | CaseDef | untpd.ParsedTry) =>
traverseChildren(tree) // assignments to candidate variables are OK here ...
case _ =>
reachable = Set.empty // ... but not here
Expand Down
13 changes: 13 additions & 0 deletions tests/explicit-nulls/pos/match-flow-typing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ def m(): String = {
if(x == null) "foo"
else x
}

def m2(): String = {
var x: String|Null = "foo"
try {
x = x
} catch {
case e => x = x
} finally {
x = x
}
if(x == null) "foo"
else x
}

0 comments on commit 74f6851

Please sign in to comment.