@@ -41,6 +41,7 @@ import transform.SymUtils._
41
41
import transform .TypeUtils ._
42
42
import reporting .trace
43
43
import Nullables .{NotNullInfo , given }
44
+ import NullOpsDecorator ._
44
45
45
46
object Typer {
46
47
@@ -417,7 +418,20 @@ class Typer extends Namer
417
418
tree.withType(ownType)
418
419
}
419
420
420
- checkStableIdentPattern(tree1, pt)
421
+ val tree2 = ownType match {
422
+ case ot : TermRef
423
+ if ctx.explicitNulls &&
424
+ pt != AssignProto && // Ensure it is not the lhs of Assign
425
+ ctx.notNullInfos.impliesNotNull(ot) =>
426
+ Apply (
427
+ TypeApply (Ident (defn.Compiletime_notNull .namedType), TypeTree (ownType.stripNull) :: Nil ),
428
+ tree1 :: Nil )
429
+ case _ =>
430
+ tree1
431
+ }
432
+
433
+
434
+ checkStableIdentPattern(tree2, pt)
421
435
}
422
436
423
437
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
@@ -1554,16 +1568,6 @@ class Typer extends Namer
1554
1568
typed(annot, defn.AnnotationClass .typeRef)
1555
1569
1556
1570
def typedValDef (vdef : untpd.ValDef , sym : Symbol )(implicit ctx : Context ): Tree = {
1557
- sym.infoOrCompleter match
1558
- case completer : Namer # Completer
1559
- if completer.creationContext.notNullInfos ne ctx.notNullInfos =>
1560
- // The RHS of a val def should know about not null facts established
1561
- // in preceding statements (unless the ValDef is completed ahead of time,
1562
- // then it is impossible).
1563
- vdef.symbol.info = Completer (completer.original)(
1564
- given completer .creationContext.withNotNullInfos(ctx.notNullInfos))
1565
- case _ =>
1566
-
1567
1571
val ValDef (name, tpt, _) = vdef
1568
1572
completeAnnotations(vdef, sym)
1569
1573
if (sym.isOneOf(GivenOrImplicit )) checkImplicitConversionDefOK(sym)
@@ -2223,6 +2227,19 @@ class Typer extends Namer
2223
2227
ctx // all preceding statements will have been executed in this case
2224
2228
case _ =>
2225
2229
ctx.withNotNullInfos(initialNotNullInfos)
2230
+ // We have to check the Completer of symbol befor typedValDef,
2231
+ // otherwise the symbol is already completed using creation context.
2232
+ mdef.getAttachment(SymOfTree ).map(s => (s, s.infoOrCompleter)) match {
2233
+ case Some ((sym, completer : Namer # Completer ))
2234
+ if completer.creationContext.notNullInfos ne defCtx.notNullInfos =>
2235
+ // The RHS of a val def should know about not null facts established
2236
+ // in preceding statements (unless the ValDef is completed ahead of time,
2237
+ // then it is impossible).
2238
+ sym.info = Completer (completer.original)(
2239
+ given completer .creationContext.withNotNullInfos(defCtx.notNullInfos))
2240
+ case _ =>
2241
+ }
2242
+
2226
2243
typed(mdef)(given defCtx ) match {
2227
2244
case mdef1 : DefDef if ! Inliner .bodyToInline(mdef1.symbol).isEmpty =>
2228
2245
buf += inlineExpansion(mdef1)
0 commit comments