Skip to content

Commit 4335575

Browse files
committed
Convert implicits to using clauses in TypeAssigner
1 parent 572ccdf commit 4335575

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait TypeAssigner {
2424
/** The qualifying class of a this or super with prefix `qual` (which might be empty).
2525
* @param packageOk The qualifier may refer to a package.
2626
*/
27-
def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(implicit ctx: Context): Symbol = {
27+
def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(using Context): Symbol = {
2828
def qualifies(sym: Symbol) =
2929
sym.isClass && (
3030
qual.isEmpty ||
@@ -47,7 +47,7 @@ trait TypeAssigner {
4747
* - abstracted over all type parameters (into a type lambda)
4848
* - where all references to `this` of the class are closed over in a RecType.
4949
*/
50-
def classBound(info: ClassInfo)(implicit ctx: Context): Type = {
50+
def classBound(info: ClassInfo)(using Context): Type = {
5151
val cls = info.cls
5252
val parentType = info.parents.reduceLeft(ctx.typeComparer.andType(_, _))
5353

@@ -96,7 +96,7 @@ trait TypeAssigner {
9696
* Type variables that would be interpolated to a type that
9797
* needs to be widened are replaced by the widened interpolation instance.
9898
*/
99-
def avoid(tp: Type, symsToAvoid: => List[Symbol])(implicit ctx: Context): Type = {
99+
def avoid(tp: Type, symsToAvoid: => List[Symbol])(using Context): Type = {
100100
val widenMap = new ApproximatingTypeMap {
101101
@threadUnsafe lazy val forbidden = symsToAvoid.toSet
102102
def toAvoid(sym: Symbol) = !sym.isStatic && forbidden.contains(sym)
@@ -157,23 +157,23 @@ trait TypeAssigner {
157157
widenMap(tp)
158158
}
159159

160-
def avoidingType(expr: Tree, bindings: List[Tree])(implicit ctx: Context): Type =
160+
def avoidingType(expr: Tree, bindings: List[Tree])(using Context): Type =
161161
avoid(expr.tpe, localSyms(bindings).filter(_.isTerm))
162162

163-
def avoidPrivateLeaks(sym: Symbol)(implicit ctx: Context): Type =
163+
def avoidPrivateLeaks(sym: Symbol)(using Context): Type =
164164
if sym.owner.isClass && !sym.isOneOf(JavaOrPrivateOrSynthetic)
165165
then checkNoPrivateLeaks(sym)
166166
else sym.info
167167

168-
private def toRepeated(tree: Tree, from: ClassSymbol)(implicit ctx: Context): Tree =
168+
private def toRepeated(tree: Tree, from: ClassSymbol)(using Context): Tree =
169169
Typed(tree, TypeTree(tree.tpe.widen.translateParameterized(from, defn.RepeatedParamClass)))
170170

171-
def seqToRepeated(tree: Tree)(implicit ctx: Context): Tree = toRepeated(tree, defn.SeqClass)
171+
def seqToRepeated(tree: Tree)(using Context): Tree = toRepeated(tree, defn.SeqClass)
172172

173-
def arrayToRepeated(tree: Tree)(implicit ctx: Context): Tree = toRepeated(tree, defn.ArrayClass)
173+
def arrayToRepeated(tree: Tree)(using Context): Tree = toRepeated(tree, defn.ArrayClass)
174174

175175
/** A denotation exists really if it exists and does not point to a stale symbol. */
176-
final def reallyExists(denot: Denotation)(implicit ctx: Context): Boolean = try
176+
final def reallyExists(denot: Denotation)(using Context): Boolean = try
177177
denot match {
178178
case denot: SymDenotation =>
179179
denot.exists && !denot.isAbsent()
@@ -196,7 +196,7 @@ trait TypeAssigner {
196196
* (2) if the owner of the denotation is a package object, it is assured
197197
* that the package object shows up as the prefix.
198198
*/
199-
def ensureAccessible(tpe: Type, superAccess: Boolean, pos: SourcePosition)(implicit ctx: Context): Type = {
199+
def ensureAccessible(tpe: Type, superAccess: Boolean, pos: SourcePosition)(using Context): Type = {
200200
def test(tpe: Type, firstTry: Boolean): Type = tpe match {
201201
case tpe: NamedType =>
202202
val pre = tpe.prefix
@@ -240,14 +240,14 @@ trait TypeAssigner {
240240
*
241241
* @see QualSkolemType, TypeOps#asSeenFrom
242242
*/
243-
def maybeSkolemizePrefix(qualType: Type, name: Name)(implicit ctx: Context): Type =
243+
def maybeSkolemizePrefix(qualType: Type, name: Name)(using Context): Type =
244244
if (name.isTermName && !ctx.isLegalPrefix(qualType))
245245
QualSkolemType(qualType)
246246
else
247247
qualType
248248

249249
/** The type of the selection `tree`, where `qual1` is the typed qualifier part. */
250-
def selectionType(tree: untpd.RefTree, qual1: Tree)(implicit ctx: Context): Type = {
250+
def selectionType(tree: untpd.RefTree, qual1: Tree)(using Context): Type = {
251251
var qualType = qual1.tpe.widenIfUnstable
252252
if (!qualType.hasSimpleKind && tree.name != nme.CONSTRUCTOR)
253253
// constructors are selected on typeconstructor, type arguments are passed afterwards
@@ -300,7 +300,7 @@ trait TypeAssigner {
300300
/** The type of the selection in `tree`, where `qual1` is the typed qualifier part.
301301
* The selection type is additionally checked for accessibility.
302302
*/
303-
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(implicit ctx: Context): Type = {
303+
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(using Context): Type = {
304304
val ownType = selectionType(tree, qual1)
305305
if (tree.hasAttachment(desugar.SuppressAccessCheck)) ownType
306306
else ensureAccessible(ownType, qual1.isInstanceOf[Super], tree.sourcePos)
@@ -311,10 +311,10 @@ trait TypeAssigner {
311311
* - typed child trees it needs to access to cpmpute that type,
312312
* - any further information it needs to access to compute that type.
313313
*/
314-
def assignType(tree: untpd.Ident, tp: Type)(implicit ctx: Context): Ident =
314+
def assignType(tree: untpd.Ident, tp: Type)(using Context): Ident =
315315
tree.withType(tp)
316316

317-
def assignType(tree: untpd.Select, qual: Tree)(implicit ctx: Context): Select = {
317+
def assignType(tree: untpd.Select, qual: Tree)(using Context): Select = {
318318
def qualType = qual.tpe.widen
319319
def arrayElemType = {
320320
qualType match {
@@ -344,15 +344,15 @@ trait TypeAssigner {
344344
/** Normalize type T appearing in a new T by following eta expansions to
345345
* avoid higher-kinded types.
346346
*/
347-
def typeOfNew(tpt: Tree)(implicit ctx: Context): Type = tpt.tpe.dealias match {
347+
def typeOfNew(tpt: Tree)(using Context): Type = tpt.tpe.dealias match {
348348
case TypeApplications.EtaExpansion(tycon) => tycon
349349
case t => tpt.tpe
350350
}
351351

352-
def assignType(tree: untpd.New, tpt: Tree)(implicit ctx: Context): New =
352+
def assignType(tree: untpd.New, tpt: Tree)(using Context): New =
353353
tree.withType(typeOfNew(tpt))
354354

355-
def assignType(tree: untpd.Literal)(implicit ctx: Context): Literal =
355+
def assignType(tree: untpd.Literal)(using Context): Literal =
356356
tree.withType {
357357
val value = tree.const
358358
value.tag match {
@@ -362,14 +362,14 @@ trait TypeAssigner {
362362
}
363363
}
364364

365-
def assignType(tree: untpd.This)(implicit ctx: Context): This = {
365+
def assignType(tree: untpd.This)(using Context): This = {
366366
val cls = qualifyingClass(tree, tree.qual.name, packageOK = false)
367367
tree.withType(
368368
if (cls.isClass) cls.thisType
369369
else errorType("not a legal qualifying class for this", tree.sourcePos))
370370
}
371371

372-
def assignType(tree: untpd.Super, qual: Tree, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = {
372+
def assignType(tree: untpd.Super, qual: Tree, mixinClass: Symbol = NoSymbol)(using Context): Super = {
373373
val mix = tree.mix
374374
qual.tpe match {
375375
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
@@ -398,7 +398,7 @@ trait TypeAssigner {
398398
/** Substitute argument type `argType` for parameter `pref` in type `tp`,
399399
* skolemizing the argument type if it is not stable and `pref` occurs in `tp`.
400400
*/
401-
def safeSubstParam(tp: Type, pref: ParamRef, argType: Type)(implicit ctx: Context): Type = {
401+
def safeSubstParam(tp: Type, pref: ParamRef, argType: Type)(using Context): Type = {
402402
val tp1 = tp.substParam(pref, argType)
403403
if ((tp1 eq tp) || argType.isStable) tp1
404404
else tp.substParam(pref, SkolemType(argType.widen))
@@ -408,15 +408,15 @@ trait TypeAssigner {
408408
* The number of parameters `params` may exceed the number of arguments.
409409
* In this case, only the common prefix is substituted.
410410
*/
411-
def safeSubstParams(tp: Type, params: List[ParamRef], argTypes: List[Type])(implicit ctx: Context): Type = argTypes match {
411+
def safeSubstParams(tp: Type, params: List[ParamRef], argTypes: List[Type])(using Context): Type = argTypes match {
412412
case argType :: argTypes1 =>
413413
val tp1 = safeSubstParam(tp, params.head, argType)
414414
safeSubstParams(tp1, params.tail, argTypes1)
415415
case Nil =>
416416
tp
417417
}
418418

419-
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
419+
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(using Context): Apply = {
420420
val ownType = fn.tpe.widen match {
421421
case fntpe: MethodType =>
422422
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
@@ -431,7 +431,7 @@ trait TypeAssigner {
431431
ConstFold(tree.withType(ownType))
432432
}
433433

434-
def assignType(tree: untpd.TypeApply, fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = {
434+
def assignType(tree: untpd.TypeApply, fn: Tree, args: List[Tree])(using Context): TypeApply = {
435435
def fail = tree.withType(errorType(err.takesNoParamsStr(fn, "type "), tree.sourcePos))
436436
fn.tpe.widen match {
437437
case pt: TypeLambda =>
@@ -502,34 +502,34 @@ trait TypeAssigner {
502502
}
503503
}
504504

505-
def assignType(tree: untpd.Typed, tpt: Tree)(implicit ctx: Context): Typed =
505+
def assignType(tree: untpd.Typed, tpt: Tree)(using Context): Typed =
506506
tree.withType(tpt.tpe)
507507

508-
def assignType(tree: untpd.NamedArg, arg: Tree)(implicit ctx: Context): NamedArg =
508+
def assignType(tree: untpd.NamedArg, arg: Tree)(using Context): NamedArg =
509509
tree.withType(arg.tpe)
510510

511-
def assignType(tree: untpd.Assign)(implicit ctx: Context): Assign =
511+
def assignType(tree: untpd.Assign)(using Context): Assign =
512512
tree.withType(defn.UnitType)
513513

514-
def assignType(tree: untpd.Block, stats: List[Tree], expr: Tree)(implicit ctx: Context): Block =
514+
def assignType(tree: untpd.Block, stats: List[Tree], expr: Tree)(using Context): Block =
515515
tree.withType(avoidingType(expr, stats))
516516

517-
def assignType(tree: untpd.Inlined, bindings: List[Tree], expansion: Tree)(implicit ctx: Context): Inlined =
517+
def assignType(tree: untpd.Inlined, bindings: List[Tree], expansion: Tree)(using Context): Inlined =
518518
tree.withType(avoidingType(expansion, bindings))
519519

520-
def assignType(tree: untpd.If, thenp: Tree, elsep: Tree)(implicit ctx: Context): If =
520+
def assignType(tree: untpd.If, thenp: Tree, elsep: Tree)(using Context): If =
521521
tree.withType(thenp.tpe | elsep.tpe)
522522

523-
def assignType(tree: untpd.Closure, meth: Tree, target: Tree)(implicit ctx: Context): Closure =
523+
def assignType(tree: untpd.Closure, meth: Tree, target: Tree)(using Context): Closure =
524524
tree.withType(
525525
if (target.isEmpty) meth.tpe.widen.toFunctionType(tree.env.length)
526526
else target.tpe)
527527

528-
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(implicit ctx: Context): CaseDef = {
528+
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(using Context): CaseDef = {
529529
val ownType =
530530
if (body.isType) {
531531
val params = new TreeAccumulator[mutable.ListBuffer[TypeSymbol]] {
532-
def apply(ps: mutable.ListBuffer[TypeSymbol], t: Tree)(implicit ctx: Context) = t match {
532+
def apply(ps: mutable.ListBuffer[TypeSymbol], t: Tree)(using Context) = t match {
533533
case t: Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
534534
case _ => foldOver(ps, t)
535535
}
@@ -542,37 +542,37 @@ trait TypeAssigner {
542542
tree.withType(ownType)
543543
}
544544

545-
def assignType(tree: untpd.Match, scrutinee: Tree, cases: List[CaseDef])(implicit ctx: Context): Match =
545+
def assignType(tree: untpd.Match, scrutinee: Tree, cases: List[CaseDef])(using Context): Match =
546546
tree.withType(ctx.typeComparer.lub(cases.tpes))
547547

548-
def assignType(tree: untpd.Labeled)(implicit ctx: Context): Labeled =
548+
def assignType(tree: untpd.Labeled)(using Context): Labeled =
549549
tree.withType(tree.bind.symbol.info)
550550

551-
def assignType(tree: untpd.Return)(implicit ctx: Context): Return =
551+
def assignType(tree: untpd.Return)(using Context): Return =
552552
tree.withType(defn.NothingType)
553553

554-
def assignType(tree: untpd.WhileDo)(implicit ctx: Context): WhileDo =
554+
def assignType(tree: untpd.WhileDo)(using Context): WhileDo =
555555
tree.withType(if (tree.cond eq EmptyTree) defn.NothingType else defn.UnitType)
556556

557-
def assignType(tree: untpd.Try, expr: Tree, cases: List[CaseDef])(implicit ctx: Context): Try =
557+
def assignType(tree: untpd.Try, expr: Tree, cases: List[CaseDef])(using Context): Try =
558558
if (cases.isEmpty) tree.withType(expr.tpe)
559559
else tree.withType(ctx.typeComparer.lub(expr.tpe :: cases.tpes))
560560

561-
def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(implicit ctx: Context): SeqLiteral = {
561+
def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(using Context): SeqLiteral = {
562562
val ownType = tree match {
563563
case tree: untpd.JavaSeqLiteral => defn.ArrayOf(elemtpt.tpe)
564564
case _ => if (ctx.erasedTypes) defn.SeqType else defn.SeqType.appliedTo(elemtpt.tpe)
565565
}
566566
tree.withType(ownType)
567567
}
568568

569-
def assignType(tree: untpd.SingletonTypeTree, ref: Tree)(implicit ctx: Context): SingletonTypeTree =
569+
def assignType(tree: untpd.SingletonTypeTree, ref: Tree)(using Context): SingletonTypeTree =
570570
tree.withType(ref.tpe)
571571

572572
/** Assign type of RefinedType.
573573
* Refinements are typed as if they were members of refinement class `refineCls`.
574574
*/
575-
def assignType(tree: untpd.RefinedTypeTree, parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(implicit ctx: Context): RefinedTypeTree = {
575+
def assignType(tree: untpd.RefinedTypeTree, parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(using Context): RefinedTypeTree = {
576576
def addRefinement(parent: Type, refinement: Tree): Type = {
577577
val rsym = refinement.symbol
578578
val rinfo = if (rsym.is(Accessor)) rsym.info.resultType else rsym.info
@@ -584,7 +584,7 @@ trait TypeAssigner {
584584
tree.withType(RecType.closeOver(rt => refined.substThis(refineCls, rt.recThis)))
585585
}
586586

587-
def assignType(tree: untpd.AppliedTypeTree, tycon: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree = {
587+
def assignType(tree: untpd.AppliedTypeTree, tycon: Tree, args: List[Tree])(using Context): AppliedTypeTree = {
588588
assert(!hasNamedArg(args) || ctx.reporter.errorsReported, tree)
589589
val tparams = tycon.tpe.typeParams
590590
val ownType =
@@ -596,52 +596,52 @@ trait TypeAssigner {
596596
tree.withType(ownType)
597597
}
598598

599-
def assignType(tree: untpd.LambdaTypeTree, tparamDefs: List[TypeDef], body: Tree)(implicit ctx: Context): LambdaTypeTree =
599+
def assignType(tree: untpd.LambdaTypeTree, tparamDefs: List[TypeDef], body: Tree)(using Context): LambdaTypeTree =
600600
tree.withType(HKTypeLambda.fromParams(tparamDefs.map(_.symbol.asType), body.tpe))
601601

602-
def assignType(tree: untpd.MatchTypeTree, bound: Tree, scrutinee: Tree, cases: List[CaseDef])(implicit ctx: Context): MatchTypeTree = {
602+
def assignType(tree: untpd.MatchTypeTree, bound: Tree, scrutinee: Tree, cases: List[CaseDef])(using Context): MatchTypeTree = {
603603
val boundType = if (bound.isEmpty) defn.AnyType else bound.tpe
604604
tree.withType(MatchType(boundType, scrutinee.tpe, cases.tpes))
605605
}
606606

607-
def assignType(tree: untpd.ByNameTypeTree, result: Tree)(implicit ctx: Context): ByNameTypeTree =
607+
def assignType(tree: untpd.ByNameTypeTree, result: Tree)(using Context): ByNameTypeTree =
608608
tree.withType(ExprType(result.tpe))
609609

610-
def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree, alias: Tree)(implicit ctx: Context): TypeBoundsTree =
610+
def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree, alias: Tree)(using Context): TypeBoundsTree =
611611
tree.withType(
612612
if !alias.isEmpty then alias.tpe
613613
else if lo eq hi then TypeAlias(lo.tpe)
614614
else TypeBounds(lo.tpe, hi.tpe))
615615

616-
def assignType(tree: untpd.Bind, sym: Symbol)(implicit ctx: Context): Bind =
616+
def assignType(tree: untpd.Bind, sym: Symbol)(using Context): Bind =
617617
tree.withType(NamedType(NoPrefix, sym))
618618

619-
def assignType(tree: untpd.Alternative, trees: List[Tree])(implicit ctx: Context): Alternative =
619+
def assignType(tree: untpd.Alternative, trees: List[Tree])(using Context): Alternative =
620620
tree.withType(ctx.typeComparer.lub(trees.tpes))
621621

622-
def assignType(tree: untpd.UnApply, proto: Type)(implicit ctx: Context): UnApply =
622+
def assignType(tree: untpd.UnApply, proto: Type)(using Context): UnApply =
623623
tree.withType(proto)
624624

625-
def assignType(tree: untpd.ValDef, sym: Symbol)(implicit ctx: Context): ValDef =
625+
def assignType(tree: untpd.ValDef, sym: Symbol)(using Context): ValDef =
626626
tree.withType(if (sym.exists) assertExists(sym.termRef) else NoType)
627627

628-
def assignType(tree: untpd.DefDef, sym: Symbol)(implicit ctx: Context): DefDef =
628+
def assignType(tree: untpd.DefDef, sym: Symbol)(using Context): DefDef =
629629
tree.withType(sym.termRef)
630630

631-
def assignType(tree: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): TypeDef =
631+
def assignType(tree: untpd.TypeDef, sym: Symbol)(using Context): TypeDef =
632632
tree.withType(sym.typeRef)
633633

634634
def assertExists(tp: Type): Type = { assert(tp != NoType); tp }
635635

636-
def assignType(tree: untpd.Import, sym: Symbol)(implicit ctx: Context): Import =
636+
def assignType(tree: untpd.Import, sym: Symbol)(using Context): Import =
637637
tree.withType(sym.termRef)
638638

639-
def assignType(tree: untpd.Annotated, arg: Tree, annot: Tree)(implicit ctx: Context): Annotated = {
639+
def assignType(tree: untpd.Annotated, arg: Tree, annot: Tree)(using Context): Annotated = {
640640
assert(tree.isType) // annotating a term is done via a Typed node, can't use Annotate directly
641641
tree.withType(AnnotatedType(arg.tpe, Annotation(annot)))
642642
}
643643

644-
def assignType(tree: untpd.PackageDef, pid: Tree)(implicit ctx: Context): PackageDef =
644+
def assignType(tree: untpd.PackageDef, pid: Tree)(using Context): PackageDef =
645645
tree.withType(pid.symbol.termRef)
646646
}
647647

0 commit comments

Comments
 (0)