@@ -588,11 +588,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
588
588
*/
589
589
def toNotNullTermRef (tree : Tree , pt : Type )(using Context ): Tree = tree.tpe match
590
590
case ref : TermRef
591
- if pt != LhsProto && // Ensure it is not the lhs of Assign
592
- ctx.notNullInfos.impliesNotNull(ref) &&
593
- // If a reference is in the context, it is already trackable at the point we add it.
594
- // Hence, we don't use isTracked in the next line, because checking use out of order is enough.
595
- ! ref.usedOutOfOrder =>
591
+ if ctx.explicitNulls
592
+ && pt != LhsProto // Ensure it is not the lhs of Assign
593
+ && ctx.notNullInfos.impliesNotNull(ref)
594
+ // If a reference is in the context, it is already trackable at the point we add it.
595
+ // Hence, we don't use isTracked in the next line, because checking use out of order is enough.
596
+ && ! ref.usedOutOfOrder =>
596
597
ref match
597
598
case OrNull (tpnn) => tree.cast(AndType (ref, tpnn))
598
599
case _ => tree
@@ -2228,7 +2229,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2228
2229
given Context = caseCtx
2229
2230
val case1 = typedCase(cas, sel, wideSelType, tpe)
2230
2231
caseCtx = Nullables .afterPatternContext(sel, case1.pat)
2231
- if ! alreadyStripped && Nullables .matchesNull(case1) then
2232
+ if ctx.explicitNulls && ! alreadyStripped && Nullables .matchesNull(case1) then
2232
2233
wideSelType = wideSelType.stripNull()
2233
2234
alreadyStripped = true
2234
2235
case1
@@ -2261,7 +2262,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2261
2262
given Context = caseCtx
2262
2263
val case1 = typedCase(cas, sel, wideSelType, pt)
2263
2264
caseCtx = Nullables .afterPatternContext(sel, case1.pat)
2264
- if ! alreadyStripped && Nullables .matchesNull(case1) then
2265
+ if ctx.explicitNulls && ! alreadyStripped && Nullables .matchesNull(case1) then
2265
2266
wideSelType = wideSelType.stripNull()
2266
2267
alreadyStripped = true
2267
2268
case1
0 commit comments