Skip to content

Commit 5e6c6c7

Browse files
committed
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 0b0e7b5 commit 5e6c6c7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,11 @@ class Typer extends Namer
431431
// If a reference is in the context, it is already trackable at the point we add it.
432432
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
433433
!ref.usedOutOfOrder =>
434-
ref.widenDealias match
435-
case OrNull(tpnn) =>
436-
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tpnn))
437-
case _ =>
434+
val tp1 = ref.widenDealias
435+
val tp2 = tp1.stripNull()
436+
if tp1 ne tp2 then
437+
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tp2))
438+
else
438439
tree
439440
case _ =>
440441
tree

0 commit comments

Comments
 (0)