Skip to content

Commit 7cff9dd

Browse files
liufengyundwijnand
authored andcommitted
Fix NonNull test
The test case `tests/explicit-nulls/neg/strip.scala` specify that null unions inside intersection types should work. After changing the scrutinee type of the extractor `OrNull` it is no longer the case. Changing the scrutinee type is still justified because it agrees with the name as well as the usage in `Types.scala`. In contrast, in `Typer.scala`, the logic is more clear without using `OrNull`.
1 parent 8275f32 commit 7cff9dd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
477477
*/
478478
def toNotNullTermRef(tree: Tree, pt: Type)(using Context): Tree = tree.tpe match
479479
case ref: TermRef
480-
if pt != AssignProto && // Ensure it is not the lhs of Assign
480+
if ctx.explicitNulls &&
481+
pt != AssignProto && // Ensure it is not the lhs of Assign
481482
ctx.notNullInfos.impliesNotNull(ref) &&
482483
// If a reference is in the context, it is already trackable at the point we add it.
483484
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
484485
!ref.usedOutOfOrder =>
485-
ref.widenDealias match
486-
case OrNull(tpnn) =>
487-
tree.cast(AndType(ref, tpnn))
488-
case _ =>
486+
val tp1 = ref.widenDealias
487+
val tp2 = tp1.stripNull()
488+
if tp1 ne tp2 then
489+
tree.cast(AndType(ref, tp2))
490+
else
489491
tree
490492
case _ =>
491493
tree

0 commit comments

Comments
 (0)