Skip to content

Commit 15d1aa0

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 15d1aa0

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
@@ -426,15 +426,17 @@ class Typer extends Namer
426426
*/
427427
def toNotNullTermRef(tree: Tree, pt: Type)(using Context): Tree = tree.tpe match
428428
case ref: TermRef
429-
if pt != AssignProto && // Ensure it is not the lhs of Assign
429+
if ctx.explicitNulls &&
430+
pt != AssignProto && // Ensure it is not the lhs of Assign
430431
ctx.notNullInfos.impliesNotNull(ref) &&
431432
// If a reference is in the context, it is already trackable at the point we add it.
432433
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
433434
!ref.usedOutOfOrder =>
434-
ref.widenDealias match
435-
case OrNull(tpnn) =>
436-
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tpnn))
437-
case _ =>
435+
val tp1 = ref.widenDealias
436+
val tp2 = tp1.stripNull()
437+
if tp1 ne tp2 then
438+
tree.select(defn.Any_typeCast).appliedToType(AndType(ref, tp2))
439+
else
438440
tree
439441
case _ =>
440442
tree

0 commit comments

Comments
 (0)