From 74f6851f0f7db62f1fcdb9e2362a6c2b5944aa85 Mon Sep 17 00:00:00 2001 From: Ondrej Lhotak Date: Mon, 24 Jul 2023 15:33:19 -0400 Subject: [PATCH] additionally include writes under try/catch/finally --- compiler/src/dotty/tools/dotc/typer/Nullables.scala | 2 +- tests/explicit-nulls/pos/match-flow-typing.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Nullables.scala b/compiler/src/dotty/tools/dotc/typer/Nullables.scala index f4748eb03849..68e3c0f8ccd6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Nullables.scala +++ b/compiler/src/dotty/tools/dotc/typer/Nullables.scala @@ -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 diff --git a/tests/explicit-nulls/pos/match-flow-typing.scala b/tests/explicit-nulls/pos/match-flow-typing.scala index cda8b25da5ff..200af36a73e0 100644 --- a/tests/explicit-nulls/pos/match-flow-typing.scala +++ b/tests/explicit-nulls/pos/match-flow-typing.scala @@ -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 +}