Skip to content

Commit c41b926

Browse files
committed
Rewrite the if stat
1 parent 2af339f commit c41b926

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,16 @@ object Nullables with
330330
def computeAssignNullable()(given Context): tree.type = tree.lhs match
331331
case TrackedRef(ref) =>
332332
val rhstp = tree.rhs.typeOpt
333-
if (rhstp.isNullType || (curCtx.explicitNulls && rhstp.isNullableUnion))
334-
// If the type of rhs is nullable (`T|Null` or `Null`), then the nullability of the
335-
// lhs variable is no longer trackable. We don't need to check whether the type `T`
336-
// is correct here, as typer will check it.
337-
tree.withNotNullInfo(NotNullInfo(Set(), Set(ref)))
338-
else if (curCtx.explicitNulls && ref.isNullableUnion)
339-
// If the initial type is nullable and the assigned value is non-null,
340-
// we add it to the NotNull
341-
tree.withNotNullInfo(NotNullInfo(Set(ref), Set()))
333+
if curCtx.explicitNulls && ref.isNullableUnion then
334+
if rhstp.isNullType || rhstp.isNullableUnion then
335+
// If the type of rhs is nullable (`T|Null` or `Null`), then the nullability of the
336+
// lhs variable is no longer trackable. We don't need to check whether the type `T`
337+
// is correct here, as typer will check it.
338+
tree.withNotNullInfo(NotNullInfo(Set(), Set(ref)))
339+
else
340+
// If the initial type is nullable and the assigned value is non-null,
341+
// we add it to the NotNull.
342+
tree.withNotNullInfo(NotNullInfo(Set(ref), Set()))
342343
else tree
343344
case _ => tree
344345

0 commit comments

Comments
 (0)