@@ -10,6 +10,7 @@ import util.Property
10
10
import Names .Name
11
11
import util .Spans .Span
12
12
import Flags .Mutable
13
+ import NullOpsDecorator ._
13
14
import collection .mutable
14
15
15
16
/** Operations for implementing a flow analysis for nullability */
@@ -258,15 +259,13 @@ object Nullables with
258
259
given assignOps : (tree : Assign )
259
260
def computeAssignNullable ()(given Context ): tree.type = tree.lhs match
260
261
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
270
269
case _ => tree
271
270
272
271
private val analyzedOps = Set (nme.EQ , nme.NE , nme.eq, nme.ne, nme.ZAND , nme.ZOR , nme.UNARY_! )
0 commit comments