@@ -41,6 +41,7 @@ import transform.SymUtils._
4141import transform .TypeUtils ._
4242import reporting .trace
4343import Nullables .{NotNullInfo , given }
44+ import NullOpsDecorator ._
4445
4546object Typer {
4647
@@ -417,7 +418,20 @@ class Typer extends Namer
417418 tree.withType(ownType)
418419 }
419420
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)
421435 }
422436
423437 /** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
@@ -1554,16 +1568,6 @@ class Typer extends Namer
15541568 typed(annot, defn.AnnotationClass .typeRef)
15551569
15561570 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-
15671571 val ValDef (name, tpt, _) = vdef
15681572 completeAnnotations(vdef, sym)
15691573 if (sym.isOneOf(GivenOrImplicit )) checkImplicitConversionDefOK(sym)
@@ -2223,6 +2227,19 @@ class Typer extends Namer
22232227 ctx // all preceding statements will have been executed in this case
22242228 case _ =>
22252229 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+
22262243 typed(mdef)(given defCtx ) match {
22272244 case mdef1 : DefDef if ! Inliner .bodyToInline(mdef1.symbol).isEmpty =>
22282245 buf += inlineExpansion(mdef1)
0 commit comments