Skip to content

Commit f0b9af5

Browse files
committed
allow nullability flow typing even in presence of pattern match
Nullability flow typing is conservatively disabled for mutable variables to which a write occurs nested inside a Tree other than some known ones, such as If and WhileDo. This is to prevent flow-sensitive reasoning for variables that are captured and written to in a closure. Pattern matches do not create a closure. This change enables nullability flow typing even for mutable variables that are written to inside a pattern match.
1 parent 2753a17 commit f0b9af5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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) =>
448+
case _: (If | WhileDo | Typed | Match | CaseDef) =>
449449
traverseChildren(tree) // assignments to candidate variables are OK here ...
450450
case _ =>
451451
reachable = Set.empty // ... but not here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def m(): String = {
2+
var x: String|Null = "foo"
3+
1 match {
4+
case 1 => x = x
5+
}
6+
if(x == null) "foo"
7+
else x
8+
}

0 commit comments

Comments
 (0)