@@ -49,14 +49,14 @@ class TreeChecker extends Phase with SymTransformer {
49
49
50
50
val NoSuperClassFlags : FlagSet = Trait | Package
51
51
52
- def testDuplicate (sym : Symbol , registry : mutable.Map [String , Symbol ], typ : String )(implicit ctx : Context ): Unit = {
52
+ def testDuplicate (sym : Symbol , registry : mutable.Map [String , Symbol ], typ : String )(using Context ): Unit = {
53
53
val name = sym.fullName.mangledString
54
54
val isDuplicate = this .flatClasses && registry.contains(name)
55
55
assert(! isDuplicate, s " $typ defined twice $sym ${sym.id} ${registry(name).id}" )
56
56
registry(name) = sym
57
57
}
58
58
59
- def checkCompanion (symd : SymDenotation )(implicit ctx : Context ): Unit = {
59
+ def checkCompanion (symd : SymDenotation )(using Context ): Unit = {
60
60
val cur = symd.linkedClass
61
61
val prev = ctx.atPhase(ctx.phase.prev) {
62
62
symd.symbol.linkedClass
@@ -66,7 +66,7 @@ class TreeChecker extends Phase with SymTransformer {
66
66
assert(cur.exists, i " companion disappeared from $symd" )
67
67
}
68
68
69
- def transformSym (symd : SymDenotation )(implicit ctx : Context ): SymDenotation = {
69
+ def transformSym (symd : SymDenotation )(using Context ): SymDenotation = {
70
70
val sym = symd.symbol
71
71
72
72
if (sym.isClass && ! sym.isAbsent()) {
@@ -92,13 +92,13 @@ class TreeChecker extends Phase with SymTransformer {
92
92
93
93
def phaseName : String = " Ycheck"
94
94
95
- def run (implicit ctx : Context ): Unit =
95
+ def run (using Context ): Unit =
96
96
if (ctx.settings.YtestPickler .value && ctx.phase.prev.isInstanceOf [Pickler ])
97
97
ctx.echo(" Skipping Ycheck after pickling with -Ytest-pickler, the returned tree contains stale symbols" )
98
98
else if (ctx.phase.prev.isCheckable)
99
99
check(ctx.base.allPhases.toIndexedSeq, ctx)
100
100
101
- private def previousPhases (phases : List [Phase ])(implicit ctx : Context ): List [Phase ] = phases match {
101
+ private def previousPhases (phases : List [Phase ])(using Context ): List [Phase ] = phases match {
102
102
case (phase : MegaPhase ) :: phases1 =>
103
103
val subPhases = phase.miniPhases
104
104
val previousSubPhases = previousPhases(subPhases.toList)
@@ -115,15 +115,15 @@ class TreeChecker extends Phase with SymTransformer {
115
115
val squahsedPhase = ctx.base.squashed(prevPhase)
116
116
ctx.echo(s " checking ${ctx.compilationUnit} after phase ${squahsedPhase}" )
117
117
118
- assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(ctx)
118
+ assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(using ctx)
119
119
120
120
val checkingCtx = ctx
121
121
.fresh
122
122
.setMode(Mode .ImplicitsEnabled )
123
123
.setReporter(new ThrowingReporter (ctx.reporter))
124
124
125
- val checker = new Checker (previousPhases(phasesToRun.toList)(ctx))
126
- try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
125
+ val checker = new Checker (previousPhases(phasesToRun.toList)(using ctx))
126
+ try checker.typedExpr(ctx.compilationUnit.tpdTree)(using checkingCtx)
127
127
catch {
128
128
case NonFatal (ex) => // TODO CHECK. Check that we are bootstrapped
129
129
implicit val ctx = checkingCtx
@@ -139,9 +139,9 @@ class TreeChecker extends Phase with SymTransformer {
139
139
private val everDefinedSyms = newMutableSymbolMap[untpd.Tree ]
140
140
141
141
// don't check value classes after typer, as the constraint about constructors doesn't hold after transform
142
- override def checkDerivedValueClass (clazz : Symbol , stats : List [Tree ])(implicit ctx : Context ): Unit = ()
142
+ override def checkDerivedValueClass (clazz : Symbol , stats : List [Tree ])(using Context ): Unit = ()
143
143
144
- def withDefinedSyms [T ](trees : List [untpd.Tree ])(op : => T )(implicit ctx : Context ): T = {
144
+ def withDefinedSyms [T ](trees : List [untpd.Tree ])(op : => T )(using Context ): T = {
145
145
var locally = List .empty[Symbol ]
146
146
for (tree <- trees) {
147
147
val sym = tree.symbol
@@ -179,7 +179,7 @@ class TreeChecker extends Phase with SymTransformer {
179
179
*
180
180
* patBoundSyms.contains(sym) <=> sym.isPatternBound
181
181
*/
182
- def withPatSyms [T ](syms : List [Symbol ])(op : => T )(implicit ctx : Context ): T = {
182
+ def withPatSyms [T ](syms : List [Symbol ])(op : => T )(using Context ): T = {
183
183
syms.foreach { sym =>
184
184
assert(
185
185
sym.isPatternBound,
@@ -203,7 +203,7 @@ class TreeChecker extends Phase with SymTransformer {
203
203
res
204
204
}
205
205
206
- def assertDefined (tree : untpd.Tree )(implicit ctx : Context ): Unit =
206
+ def assertDefined (tree : untpd.Tree )(using Context ): Unit =
207
207
if (tree.symbol.maybeOwner.isTerm) {
208
208
val sym = tree.symbol
209
209
assert(
@@ -219,14 +219,14 @@ class TreeChecker extends Phase with SymTransformer {
219
219
}
220
220
221
221
/** assert Java classes are not used as objects */
222
- def assertIdentNotJavaClass (tree : Tree )(implicit ctx : Context ): Unit = tree match {
222
+ def assertIdentNotJavaClass (tree : Tree )(using Context ): Unit = tree match {
223
223
case _ : untpd.Ident =>
224
224
assert(! tree.symbol.isAllOf(JavaModule ), " Java class can't be used as value: " + tree)
225
225
case _ =>
226
226
}
227
227
228
228
/** check Java classes are not used as objects */
229
- def checkIdentNotJavaClass (tree : Tree )(implicit ctx : Context ): Unit = tree match {
229
+ def checkIdentNotJavaClass (tree : Tree )(using Context ): Unit = tree match {
230
230
// case tree: untpd.Ident =>
231
231
// case tree: untpd.Select =>
232
232
// case tree: untpd.Bind =>
@@ -284,10 +284,10 @@ class TreeChecker extends Phase with SymTransformer {
284
284
* made `private` in phase `UnlinkErasedDecls`. These symbols will be removed
285
285
* completely in phase `Erasure` if they are defined in a currently compiled unit.
286
286
*/
287
- override def excludeFromDoubleDeclCheck (sym : Symbol )(implicit ctx : Context ): Boolean =
287
+ override def excludeFromDoubleDeclCheck (sym : Symbol )(using Context ): Boolean =
288
288
sym.isEffectivelyErased && sym.is(Private ) && ! sym.initial.is(Private )
289
289
290
- override def typed (tree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = {
290
+ override def typed (tree : untpd.Tree , pt : Type = WildcardType )(using Context ): Tree = {
291
291
val tpdTree = super .typed(tree, pt)
292
292
Typer .assertPositioned(tree)
293
293
if (ctx.erasedTypes)
@@ -297,7 +297,7 @@ class TreeChecker extends Phase with SymTransformer {
297
297
tpdTree
298
298
}
299
299
300
- override def typedUnadapted (tree : untpd.Tree , pt : Type , locked : TypeVars )(implicit ctx : Context ): Tree = {
300
+ override def typedUnadapted (tree : untpd.Tree , pt : Type , locked : TypeVars )(using Context ): Tree = {
301
301
val res = tree match {
302
302
case _ : untpd.TypedSplice | _ : untpd.Thicket | _ : EmptyValDef [? ] =>
303
303
super .typedUnadapted(tree, pt, locked)
@@ -325,21 +325,21 @@ class TreeChecker extends Phase with SymTransformer {
325
325
res
326
326
}
327
327
328
- def checkNotRepeated (tree : Tree )(implicit ctx : Context ): tree.type = {
328
+ def checkNotRepeated (tree : Tree )(using Context ): tree.type = {
329
329
def allowedRepeated = tree.tpe.widen.isRepeatedParam
330
330
331
331
assert(! tree.tpe.widen.isRepeatedParam || allowedRepeated, i " repeated parameter type not allowed here: $tree" )
332
332
tree
333
333
}
334
334
335
335
/** Check that all methods have MethodicType */
336
- def isMethodType (pt : Type )(implicit ctx : Context ): Boolean = pt match {
336
+ def isMethodType (pt : Type )(using Context ): Boolean = pt match {
337
337
case at : AnnotatedType => isMethodType(at.parent)
338
338
case _ : MethodicType => true // MethodType, ExprType, PolyType
339
339
case _ => false
340
340
}
341
341
342
- override def typedIdent (tree : untpd.Ident , pt : Type )(implicit ctx : Context ): Tree = {
342
+ override def typedIdent (tree : untpd.Ident , pt : Type )(using Context ): Tree = {
343
343
assert(tree.isTerm || ! ctx.isAfterTyper, tree.show + " at " + ctx.phase)
344
344
assert(tree.isType || ctx.mode.is(Mode .Pattern ) && untpd.isWildcardArg(tree) || ! needsSelect(tree.tpe), i " bad type ${tree.tpe} for $tree # ${tree.uniqueId}" )
345
345
assertDefined(tree)
@@ -351,7 +351,7 @@ class TreeChecker extends Phase with SymTransformer {
351
351
* calling `member` on the qualifier type.
352
352
* Approximately means: The two symbols might be different but one still overrides the other.
353
353
*/
354
- override def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree = {
354
+ override def typedSelect (tree : untpd.Select , pt : Type )(using Context ): Tree = {
355
355
assert(tree.isTerm || ! ctx.isAfterTyper, tree.show + " at " + ctx.phase)
356
356
val tpe = tree.typeOpt
357
357
val sym = tree.symbol
@@ -380,14 +380,14 @@ class TreeChecker extends Phase with SymTransformer {
380
380
checkNotRepeated(super .typedSelect(tree, pt))
381
381
}
382
382
383
- override def typedThis (tree : untpd.This )(implicit ctx : Context ): Tree = {
383
+ override def typedThis (tree : untpd.This )(using Context ): Tree = {
384
384
val res = super .typedThis(tree)
385
385
val cls = res.symbol
386
386
assert(cls.isStaticOwner || ctx.owner.isContainedIn(cls), i " error while typing $tree, ${ctx.owner} is not contained in $cls" )
387
387
res
388
388
}
389
389
390
- private def checkOwner (tree : untpd.Tree )(implicit ctx : Context ): Unit = {
390
+ private def checkOwner (tree : untpd.Tree )(using Context ): Unit = {
391
391
def ownerMatches (symOwner : Symbol , ctxOwner : Symbol ): Boolean =
392
392
symOwner == ctxOwner ||
393
393
ctxOwner.isWeakOwner && ownerMatches(symOwner, ctxOwner.owner)
@@ -396,7 +396,7 @@ class TreeChecker extends Phase with SymTransformer {
396
396
i " owner chain = ${tree.symbol.ownersIterator.toList}%, %, ctxOwners = ${ctx.outersIterator.map(_.owner).toList}%, % " )
397
397
}
398
398
399
- override def typedClassDef (cdef : untpd.TypeDef , cls : ClassSymbol )(implicit ctx : Context ): Tree = {
399
+ override def typedClassDef (cdef : untpd.TypeDef , cls : ClassSymbol )(using Context ): Tree = {
400
400
val TypeDef (_, impl @ Template (constr, _, _, _)) = cdef
401
401
assert(cdef.symbol == cls)
402
402
assert(impl.symbol.owner == cls)
@@ -421,7 +421,7 @@ class TreeChecker extends Phase with SymTransformer {
421
421
super .typedClassDef(cdef, cls)
422
422
}
423
423
424
- override def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(implicit ctx : Context ): Tree =
424
+ override def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(using Context ): Tree =
425
425
withDefinedSyms(ddef.tparams) {
426
426
withDefinedSyms(ddef.vparamss.flatten) {
427
427
if (! sym.isClassConstructor && ! (sym.name eq nme.STATIC_CONSTRUCTOR ))
@@ -440,12 +440,12 @@ class TreeChecker extends Phase with SymTransformer {
440
440
}
441
441
}
442
442
443
- override def typedCase (tree : untpd.CaseDef , sel : Tree , selType : Type , pt : Type )(implicit ctx : Context ): CaseDef =
443
+ override def typedCase (tree : untpd.CaseDef , sel : Tree , selType : Type , pt : Type )(using Context ): CaseDef =
444
444
withPatSyms(tpd.patVars(tree.pat.asInstanceOf [tpd.Tree ])) {
445
445
super .typedCase(tree, sel, selType, pt)
446
446
}
447
447
448
- override def typedClosure (tree : untpd.Closure , pt : Type )(implicit ctx : Context ): Tree = {
448
+ override def typedClosure (tree : untpd.Closure , pt : Type )(using Context ): Tree = {
449
449
if (! ctx.phase.lambdaLifted) nestingBlock match {
450
450
case block @ Block ((meth : DefDef ) :: Nil , closure : Closure ) =>
451
451
assert(meth.symbol == closure.meth.symbol, " closure.meth symbol not equal to method symbol. Block: " + block.show)
@@ -459,10 +459,10 @@ class TreeChecker extends Phase with SymTransformer {
459
459
super .typedClosure(tree, pt)
460
460
}
461
461
462
- override def typedBlock (tree : untpd.Block , pt : Type )(implicit ctx : Context ): Tree =
462
+ override def typedBlock (tree : untpd.Block , pt : Type )(using Context ): Tree =
463
463
withBlock(tree) { withDefinedSyms(tree.stats) { super .typedBlock(tree, pt) } }
464
464
465
- override def typedInlined (tree : untpd.Inlined , pt : Type )(implicit ctx : Context ): Tree =
465
+ override def typedInlined (tree : untpd.Inlined , pt : Type )(using Context ): Tree =
466
466
withDefinedSyms(tree.bindings) { super .typedInlined(tree, pt) }
467
467
468
468
/** Check that all defined symbols have legal owners.
@@ -472,7 +472,7 @@ class TreeChecker extends Phase with SymTransformer {
472
472
* is that we should be able to pull out an expression as an initializer
473
473
* of a helper value without having to do a change owner traversal of the expression.
474
474
*/
475
- override def typedStats (trees : List [untpd.Tree ], exprOwner : Symbol )(implicit ctx : Context ): (List [Tree ], Context ) = {
475
+ override def typedStats (trees : List [untpd.Tree ], exprOwner : Symbol )(using Context ): (List [Tree ], Context ) = {
476
476
for (tree <- trees) tree match {
477
477
case tree : untpd.DefTree => checkOwner(tree)
478
478
case _ : untpd.Thicket => assert(false , i " unexpanded thicket $tree in statement sequence $trees% \n % " )
@@ -481,12 +481,12 @@ class TreeChecker extends Phase with SymTransformer {
481
481
super .typedStats(trees, exprOwner)
482
482
}
483
483
484
- override def typedLabeled (tree : untpd.Labeled )(implicit ctx : Context ): Labeled = {
484
+ override def typedLabeled (tree : untpd.Labeled )(using Context ): Labeled = {
485
485
checkOwner(tree.bind)
486
486
withDefinedSyms(tree.bind :: Nil ) { super .typedLabeled(tree) }
487
487
}
488
488
489
- override def typedReturn (tree : untpd.Return )(implicit ctx : Context ): Return = {
489
+ override def typedReturn (tree : untpd.Return )(using Context ): Return = {
490
490
val tree1 = super .typedReturn(tree)
491
491
val from = tree1.from
492
492
val fromSym = from.symbol
@@ -495,15 +495,15 @@ class TreeChecker extends Phase with SymTransformer {
495
495
tree1
496
496
}
497
497
498
- override def typedWhileDo (tree : untpd.WhileDo )(implicit ctx : Context ): Tree = {
498
+ override def typedWhileDo (tree : untpd.WhileDo )(using Context ): Tree = {
499
499
assert((tree.cond ne EmptyTree ) || ctx.phase.refChecked, i " invalid empty condition in while at $tree" )
500
500
super .typedWhileDo(tree)
501
501
}
502
502
503
- override def ensureNoLocalRefs (tree : Tree , pt : Type , localSyms : => List [Symbol ])(implicit ctx : Context ): Tree =
503
+ override def ensureNoLocalRefs (tree : Tree , pt : Type , localSyms : => List [Symbol ])(using Context ): Tree =
504
504
tree
505
505
506
- override def adapt (tree : Tree , pt : Type , locked : TypeVars )(implicit ctx : Context ): Tree = {
506
+ override def adapt (tree : Tree , pt : Type , locked : TypeVars )(using Context ): Tree = {
507
507
def isPrimaryConstructorReturn =
508
508
ctx.owner.isPrimaryConstructor && pt.isRef(ctx.owner.owner) && tree.tpe.isRef(defn.UnitClass )
509
509
def infoStr (tp : Type ) = tp match {
@@ -527,15 +527,15 @@ class TreeChecker extends Phase with SymTransformer {
527
527
tree
528
528
}
529
529
530
- override def simplify (tree : Tree , pt : Type , locked : TypeVars )(implicit ctx : Context ): tree.type = tree
530
+ override def simplify (tree : Tree , pt : Type , locked : TypeVars )(using Context ): tree.type = tree
531
531
}
532
532
533
533
/**
534
534
* Checks that `New` nodes are always wrapped inside `Select` nodes.
535
535
*/
536
- def assertSelectWrapsNew (tree : Tree )(implicit ctx : Context ): Unit =
536
+ def assertSelectWrapsNew (tree : Tree )(using Context ): Unit =
537
537
(new TreeAccumulator [tpd.Tree ] {
538
- override def apply (parent : Tree , tree : Tree )(implicit ctx : Context ): Tree = {
538
+ override def apply (parent : Tree , tree : Tree )(using Context ): Tree = {
539
539
tree match {
540
540
case tree : New if ! parent.isInstanceOf [tpd.Select ] =>
541
541
assert(assertion = false , i " `New` node must be wrapped in a `Select`: \n parent = ${parent.show}\n child = ${tree.show}" )
@@ -554,7 +554,7 @@ object TreeChecker {
554
554
/** - Check that TypeParamRefs and MethodParams refer to an enclosing type.
555
555
* - Check that all type variables are instantiated.
556
556
*/
557
- def checkNoOrphans (tp0 : Type , tree : untpd.Tree = untpd.EmptyTree )(implicit ctx : Context ): Type = new TypeMap () {
557
+ def checkNoOrphans (tp0 : Type , tree : untpd.Tree = untpd.EmptyTree )(using Context ): Type = new TypeMap () {
558
558
val definedBinders = new java.util.IdentityHashMap [Type , Any ]
559
559
def apply (tp : Type ): Type = {
560
560
tp match {
0 commit comments