Skip to content

Commit bdbde1d

Browse files
committed
Simplify case
1 parent 49d550e commit bdbde1d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.Property
1010
import Names.Name
1111
import util.Spans.Span
1212
import Flags.Mutable
13+
import NullOpsDecorator._
1314
import collection.mutable
1415

1516
/** Operations for implementing a flow analysis for nullability */
@@ -258,15 +259,13 @@ object Nullables with
258259
given assignOps: (tree: Assign)
259260
def computeAssignNullable()(given Context): tree.type = tree.lhs match
260261
case TrackedRef(ref) =>
261-
def withoutRef: tree.type = tree.withNotNullInfo(NotNullInfo(Set(), Set(ref)))
262-
tree.rhs.typeOpt match
263-
// If the type of rhs is `T|Null`, then the nullability of the lhs variable is no longer
264-
// trackable. We don't need to check whether the type `T` is correct here, as typer will
265-
// check it.
266-
case OrNull(_) => withoutRef
267-
// If the type of rhs is Null, we discard its NotNullInfo.
268-
case tp if tp.isNullType => withoutRef
269-
case _ => tree
262+
val rhstp = tree.rhs.typeOpt
263+
if (rhstp.isNullType || rhstp.isNullableUnion)
264+
// If the type of rhs is nullable (`T|Null` or `Null`), then the nullability of the
265+
// lhs variable is no longer trackable. We don't need to check whether the type `T`
266+
// is correct here, as typer will check it.
267+
tree.withNotNullInfo(NotNullInfo(Set(), Set(ref)))
268+
else tree
270269
case _ => tree
271270

272271
private val analyzedOps = Set(nme.EQ, nme.NE, nme.eq, nme.ne, nme.ZAND, nme.ZOR, nme.UNARY_!)

0 commit comments

Comments
 (0)