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