@@ -70,8 +70,8 @@ trait NamerContextOps {
70
70
71
71
/** The symbol (stored in some typer's symTree) of an enclosing context definition */
72
72
def symOfContextTree (tree : untpd.Tree ): Symbol = {
73
- def go (ctx : Context ): Symbol =
74
- ctx .typeAssigner match {
73
+ def go (contxt : Context ): Symbol =
74
+ contxt .typeAssigner match {
75
75
case typer : Typer =>
76
76
tree.getAttachment(typer.SymOfTree ) match {
77
77
case Some (sym) => sym
@@ -131,7 +131,7 @@ trait NamerContextOps {
131
131
termParamss
132
132
133
133
/** The method type corresponding to given parameters and result type */
134
- def methodType (typeParams : List [Symbol ], valueParamss : List [List [Symbol ]], resultType : Type , isJava : Boolean = false )(implicit ctx : Context ): Type = {
134
+ def methodType (typeParams : List [Symbol ], valueParamss : List [List [Symbol ]], resultType : Type , isJava : Boolean = false )(using Context ): Type = {
135
135
val monotpe =
136
136
valueParamss.foldRight(resultType) { (params, resultType) =>
137
137
val (isContextual, isImplicit, isErased) =
@@ -162,7 +162,7 @@ trait NamerContextOps {
162
162
163
163
object NamerContextOps {
164
164
/** Find moduleClass/sourceModule in effective scope */
165
- private def findModuleBuddy (name : Name , scope : Scope )(implicit ctx : Context ) = {
165
+ private def findModuleBuddy (name : Name , scope : Scope )(using Context ) = {
166
166
val it = scope.lookupAll(name).filter(_.is(Module ))
167
167
if (it.hasNext) it.next()
168
168
else NoSymbol .assertingErrorsReported(s " no companion $name in $scope" )
@@ -238,7 +238,7 @@ class Namer { typer: Typer =>
238
238
private var lateCompile = false
239
239
240
240
/** The symbol of the given expanded tree. */
241
- def symbolOfTree (tree : Tree )(implicit ctx : Context ): Symbol = {
241
+ def symbolOfTree (tree : Tree )(using Context ): Symbol = {
242
242
val xtree = expanded(tree)
243
243
xtree.getAttachment(TypedAhead ) match {
244
244
case Some (ttree) => ttree.symbol
@@ -247,7 +247,7 @@ class Namer { typer: Typer =>
247
247
}
248
248
249
249
/** The enclosing class with given name; error if none exists */
250
- def enclosingClassNamed (name : TypeName , span : Span )(implicit ctx : Context ): Symbol =
250
+ def enclosingClassNamed (name : TypeName , span : Span )(using Context ): Symbol =
251
251
if (name.isEmpty) NoSymbol
252
252
else {
253
253
val cls = ctx.owner.enclosingClassNamed(name)
@@ -257,7 +257,7 @@ class Namer { typer: Typer =>
257
257
}
258
258
259
259
/** Record `sym` as the symbol defined by `tree` */
260
- def recordSym (sym : Symbol , tree : Tree )(implicit ctx : Context ): Symbol = {
260
+ def recordSym (sym : Symbol , tree : Tree )(using Context ): Symbol = {
261
261
for (refs <- tree.removeAttachment(References ); ref <- refs) ref.watching(sym)
262
262
tree.pushAttachment(SymOfTree , sym)
263
263
sym
@@ -309,7 +309,7 @@ class Namer { typer: Typer =>
309
309
/** If this tree is a member def or an import, create a symbol of it
310
310
* and store in symOfTree map.
311
311
*/
312
- def createSymbol (tree : Tree )(implicit ctx : Context ): Symbol = {
312
+ def createSymbol (tree : Tree )(using Context ): Symbol = {
313
313
314
314
def privateWithinClass (mods : Modifiers ) =
315
315
enclosingClassNamed(mods.privateWithin, tree.span)
@@ -422,7 +422,7 @@ class Namer { typer: Typer =>
422
422
createOrRefine[Symbol ](tree, name, flags, ctx.owner, _ => info,
423
423
(fs, _, pwithin) => ctx.newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan))
424
424
case tree : Import =>
425
- recordSym(ctx.newImportSymbol(ctx.owner, new Completer (tree), tree.span), tree)
425
+ recordSym(ctx.newImportSymbol(ctx.owner, Completer (tree)(ctx ), tree.span), tree)
426
426
case _ =>
427
427
NoSymbol
428
428
}
@@ -431,7 +431,7 @@ class Namer { typer: Typer =>
431
431
/** If `sym` exists, enter it in effective scope. Check that
432
432
* package members are not entered twice in the same run.
433
433
*/
434
- def enterSymbol (sym : Symbol )(implicit ctx : Context ): Symbol = {
434
+ def enterSymbol (sym : Symbol )(using Context ): Symbol = {
435
435
if (sym.exists) {
436
436
typr.println(s " entered: $sym in ${ctx.owner}" )
437
437
ctx.enter(sym)
@@ -440,7 +440,7 @@ class Namer { typer: Typer =>
440
440
}
441
441
442
442
/** Create package if it does not yet exist. */
443
- private def createPackageSymbol (pid : RefTree )(implicit ctx : Context ): Symbol = {
443
+ private def createPackageSymbol (pid : RefTree )(using Context ): Symbol = {
444
444
val pkgOwner = pid match {
445
445
case Ident (_) => if (ctx.owner eq defn.EmptyPackageClass ) defn.RootClass else ctx.owner
446
446
case Select (qual : RefTree , _) => createPackageSymbol(qual).moduleClass
@@ -469,7 +469,7 @@ class Namer { typer: Typer =>
469
469
}
470
470
471
471
/** Expand tree and store in `expandedTree` */
472
- def expand (tree : Tree )(implicit ctx : Context ): Unit = {
472
+ def expand (tree : Tree )(using Context ): Unit = {
473
473
def record (expanded : Tree ) =
474
474
if (expanded `ne` tree) {
475
475
typr.println(i " Expansion: $tree expands to $expanded" )
@@ -483,7 +483,7 @@ class Namer { typer: Typer =>
483
483
}
484
484
485
485
/** The expanded version of this tree, or tree itself if not expanded */
486
- def expanded (tree : Tree )(implicit ctx : Context ): Tree = tree match {
486
+ def expanded (tree : Tree )(using Context ): Tree = tree match {
487
487
case _ : DefTree | _ : PackageDef => tree.attachmentOrElse(ExpandedTree , tree)
488
488
case _ => tree
489
489
}
@@ -492,7 +492,7 @@ class Namer { typer: Typer =>
492
492
* not also defined in `xstats`, invalidate it by setting its info to
493
493
* NoType.
494
494
*/
495
- def invalidateCompanions (pkg : Symbol , xstats : List [untpd.Tree ])(implicit ctx : Context ): Unit = {
495
+ def invalidateCompanions (pkg : Symbol , xstats : List [untpd.Tree ])(using Context ): Unit = {
496
496
val definedNames = xstats collect { case stat : NameTree => stat.name }
497
497
def invalidate (name : TypeName ) =
498
498
if (! (definedNames contains name)) {
@@ -507,19 +507,19 @@ class Namer { typer: Typer =>
507
507
}
508
508
509
509
/** Expand tree and create top-level symbols for statement and enter them into symbol table */
510
- def index (stat : Tree )(implicit ctx : Context ): Context = {
510
+ def index (stat : Tree )(using Context ): Context = {
511
511
expand(stat)
512
512
indexExpanded(stat)
513
513
}
514
514
515
515
/** Create top-level symbols for all statements in the expansion of this statement and
516
516
* enter them into symbol table
517
517
*/
518
- def indexExpanded (origStat : Tree )(implicit ctx : Context ): Context = {
518
+ def indexExpanded (origStat : Tree )(using Context ): Context = {
519
519
def recur (stat : Tree ): Context = stat match {
520
520
case pcl : PackageDef =>
521
521
val pkg = createPackageSymbol(pcl.pid)
522
- index(pcl.stats)(ctx.fresh.setOwner(pkg.moduleClass))
522
+ index(pcl.stats)(using ctx.fresh.setOwner(pkg.moduleClass))
523
523
invalidateCompanions(pkg, Trees .flatten(pcl.stats map expanded))
524
524
setDocstring(pkg, stat)
525
525
ctx
@@ -540,15 +540,15 @@ class Namer { typer: Typer =>
540
540
}
541
541
542
542
/** Determines whether this field holds an enum constant. */
543
- def isEnumConstant (vd : ValDef )(implicit ctx : Context ): Boolean =
543
+ def isEnumConstant (vd : ValDef )(using Context ): Boolean =
544
544
vd.mods.isAllOf(JavaEnumValue )
545
545
546
546
/** Add child annotation for `child` to annotations of `cls`. The annotation
547
547
* is added at the correct insertion point, so that Child annotations appear
548
548
* in reverse order of their start positions.
549
549
* @pre `child` must have a position.
550
550
*/
551
- final def addChild (cls : Symbol , child : Symbol )(implicit ctx : Context ): Unit = {
551
+ final def addChild (cls : Symbol , child : Symbol )(using Context ): Unit = {
552
552
val childStart = if (child.span.exists) child.span.start else - 1
553
553
def insertInto (annots : List [Annotation ]): List [Annotation ] =
554
554
annots.find(_.symbol == defn.ChildAnnot ) match {
@@ -567,15 +567,15 @@ class Namer { typer: Typer =>
567
567
}
568
568
569
569
/** Add java enum constants */
570
- def addEnumConstants (mdef : DefTree , sym : Symbol )(implicit ctx : Context ): Unit = mdef match {
570
+ def addEnumConstants (mdef : DefTree , sym : Symbol )(using Context ): Unit = mdef match {
571
571
case vdef : ValDef if (isEnumConstant(vdef)) =>
572
572
val enumClass = sym.owner.linkedClass
573
573
if (! enumClass.is(Sealed )) enumClass.setFlag(Flags .AbstractSealed )
574
574
addChild(enumClass, sym)
575
575
case _ =>
576
576
}
577
577
578
- def setDocstring (sym : Symbol , tree : Tree )(implicit ctx : Context ): Unit = tree match {
578
+ def setDocstring (sym : Symbol , tree : Tree )(using Context ): Unit = tree match {
579
579
case t : MemberDef if t.rawComment.isDefined =>
580
580
ctx.docCtx.foreach(_.addDocstring(sym, t.rawComment))
581
581
case _ => ()
@@ -584,7 +584,7 @@ class Namer { typer: Typer =>
584
584
/** Create top-level symbols for statements and enter them into symbol table
585
585
* @return A context that reflects all imports in `stats`.
586
586
*/
587
- def index (stats : List [Tree ])(implicit ctx : Context ): Context = {
587
+ def index (stats : List [Tree ])(using Context ): Context = {
588
588
589
589
// module name -> (stat, moduleCls | moduleVal)
590
590
val moduleClsDef = mutable.Map [TypeName , (Tree , TypeDef )]()
@@ -692,14 +692,14 @@ class Namer { typer: Typer =>
692
692
}
693
693
694
694
/** Create links between companion object and companion class */
695
- def createLinks (classTree : TypeDef , moduleTree : TypeDef )(implicit ctx : Context ) = {
695
+ def createLinks (classTree : TypeDef , moduleTree : TypeDef )(using Context ) = {
696
696
val claz = ctx.effectiveScope.lookup(classTree.name)
697
697
val modl = ctx.effectiveScope.lookup(moduleTree.name)
698
698
modl.registerCompanion(claz)
699
699
claz.registerCompanion(modl)
700
700
}
701
701
702
- def createCompanionLinks (implicit ctx : Context ): Unit = {
702
+ def createCompanionLinks (using Context ): Unit = {
703
703
val classDef = mutable.Map [TypeName , TypeDef ]()
704
704
val moduleDef = mutable.Map [TypeName , TypeDef ]()
705
705
@@ -759,16 +759,16 @@ class Namer { typer: Typer =>
759
759
760
760
stats.foreach(expand)
761
761
mergeCompanionDefs()
762
- val ctxWithStats = stats.foldLeft(ctx)((ctx, stat) => indexExpanded(stat)(ctx))
763
- createCompanionLinks(ctxWithStats)
762
+ val ctxWithStats = stats.foldLeft(ctx)((ctx, stat) => indexExpanded(stat)(using ctx))
763
+ createCompanionLinks(using ctxWithStats)
764
764
ctxWithStats
765
765
}
766
766
767
767
/** Index symbols in `tree` while asserting the `lateCompile` flag.
768
768
* This will cause any old top-level symbol with the same fully qualified
769
769
* name as a newly created symbol to be replaced.
770
770
*/
771
- def lateEnter (tree : Tree )(implicit ctx : Context ): Context = {
771
+ def lateEnter (tree : Tree )(using Context ): Context = {
772
772
val saved = lateCompile
773
773
lateCompile = true
774
774
try index(tree :: Nil ) finally lateCompile = saved
@@ -778,27 +778,27 @@ class Namer { typer: Typer =>
778
778
* Nothing if no wildcard imports of this kind exist
779
779
* Any if there are unbounded wildcard imports of this kind
780
780
*/
781
- def importBound (sels : List [untpd.ImportSelector ], isGiven : Boolean )(implicit ctx : Context ): Type =
781
+ def importBound (sels : List [untpd.ImportSelector ], isGiven : Boolean )(using Context ): Type =
782
782
sels.foldLeft(defn.NothingType : Type ) { (bound, sel) =>
783
783
if sel.isWildcard && sel.isGiven == isGiven then
784
784
if sel.bound.isEmpty then defn.AnyType
785
785
else bound | typedAheadType(sel.bound).tpe
786
786
else bound
787
787
}
788
788
789
- def missingType (sym : Symbol , modifier : String )(implicit ctx : Context ): Unit = {
789
+ def missingType (sym : Symbol , modifier : String )(using Context ): Unit = {
790
790
ctx.error(s " ${modifier}type of implicit definition needs to be given explicitly " , sym.sourcePos)
791
791
sym.resetFlag(GivenOrImplicit )
792
792
}
793
793
794
794
/** The completer of a symbol defined by a member def or import (except ClassSymbols) */
795
- class Completer (val original : Tree )(implicit ctx : Context ) extends LazyType with SymbolLoaders .SecondCompleter {
795
+ class Completer (val original : Tree )(ictx : Context ) extends LazyType with SymbolLoaders .SecondCompleter {
796
796
797
797
protected def localContext (owner : Symbol ): FreshContext = ctx.fresh.setOwner(owner).setTree(original)
798
798
799
799
/** The context with which this completer was created */
800
- def creationContext : Context = ctx
801
- ctx .typerState.markShared()
800
+ given creationContext as Context = ictx
801
+ ictx .typerState.markShared()
802
802
803
803
protected def typeSig (sym : Symbol ): Type = original match {
804
804
case original : ValDef =>
@@ -820,10 +820,10 @@ class Namer { typer: Typer =>
820
820
}
821
821
}
822
822
823
- final override def complete (denot : SymDenotation )(implicit ctx : Context ): Unit = {
824
- if (Config .showCompletions && ctx.typerState != this .ctx .typerState) {
823
+ final override def complete (denot : SymDenotation )(using Context ): Unit = {
824
+ if (Config .showCompletions && ctx.typerState != creationContext .typerState) {
825
825
def levels (c : Context ): Int =
826
- if (c.typerState eq this .ctx .typerState) 0
826
+ if (c.typerState eq creationContext .typerState) 0
827
827
else if (c.typerState == null ) - 1
828
828
else if (c.outer.typerState == c.typerState) levels(c.outer)
829
829
else levels(c.outer) + 1
@@ -1188,7 +1188,7 @@ class Namer { typer: Typer =>
1188
1188
localCtx = completerCtx.inClassContext(selfInfo)
1189
1189
1190
1190
index(constr)
1191
- index(rest)(localCtx)
1191
+ index(rest)(using localCtx)
1192
1192
1193
1193
symbolOfTree(constr).info.stripPoly match // Completes constr symbol as a side effect
1194
1194
case mt : MethodType if cls.is(Case ) && mt.isParamDependent =>
@@ -1224,7 +1224,7 @@ class Namer { typer: Typer =>
1224
1224
if (ptype.typeParams.isEmpty) ptype
1225
1225
else {
1226
1226
if (denot.is(ModuleClass ) && denot.sourceModule.isOneOf(GivenOrImplicit ))
1227
- missingType(denot.symbol, " parent " )(creationContext)
1227
+ missingType(denot.symbol, " parent " )(using creationContext)
1228
1228
fullyDefinedType(typedAheadExpr(parent).tpe, " class parent" , parent.span)
1229
1229
}
1230
1230
case _ =>
0 commit comments