diff --git a/compiler/src/dotty/tools/dotc/typer/Nullables.scala b/compiler/src/dotty/tools/dotc/typer/Nullables.scala index e7ef771a414a..470e9d241933 100644 --- a/compiler/src/dotty/tools/dotc/typer/Nullables.scala +++ b/compiler/src/dotty/tools/dotc/typer/Nullables.scala @@ -456,7 +456,7 @@ object Nullables: else candidates -= name case None => traverseChildren(tree) - case _: (If | WhileDo | Typed) => + 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 new file mode 100644 index 000000000000..200af36a73e0 --- /dev/null +++ b/tests/explicit-nulls/pos/match-flow-typing.scala @@ -0,0 +1,21 @@ +def m(): String = { + var x: String|Null = "foo" + 1 match { + case 1 => x = x + } + 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 +}