@@ -24,7 +24,7 @@ trait TypeAssigner {
24
24
/** The qualifying class of a this or super with prefix `qual` (which might be empty).
25
25
* @param packageOk The qualifier may refer to a package.
26
26
*/
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 = {
28
28
def qualifies (sym : Symbol ) =
29
29
sym.isClass && (
30
30
qual.isEmpty ||
@@ -47,7 +47,7 @@ trait TypeAssigner {
47
47
* - abstracted over all type parameters (into a type lambda)
48
48
* - where all references to `this` of the class are closed over in a RecType.
49
49
*/
50
- def classBound (info : ClassInfo )(implicit ctx : Context ): Type = {
50
+ def classBound (info : ClassInfo )(using Context ): Type = {
51
51
val cls = info.cls
52
52
val parentType = info.parents.reduceLeft(ctx.typeComparer.andType(_, _))
53
53
@@ -96,7 +96,7 @@ trait TypeAssigner {
96
96
* Type variables that would be interpolated to a type that
97
97
* needs to be widened are replaced by the widened interpolation instance.
98
98
*/
99
- def avoid (tp : Type , symsToAvoid : => List [Symbol ])(implicit ctx : Context ): Type = {
99
+ def avoid (tp : Type , symsToAvoid : => List [Symbol ])(using Context ): Type = {
100
100
val widenMap = new ApproximatingTypeMap {
101
101
@ threadUnsafe lazy val forbidden = symsToAvoid.toSet
102
102
def toAvoid (sym : Symbol ) = ! sym.isStatic && forbidden.contains(sym)
@@ -157,23 +157,23 @@ trait TypeAssigner {
157
157
widenMap(tp)
158
158
}
159
159
160
- def avoidingType (expr : Tree , bindings : List [Tree ])(implicit ctx : Context ): Type =
160
+ def avoidingType (expr : Tree , bindings : List [Tree ])(using Context ): Type =
161
161
avoid(expr.tpe, localSyms(bindings).filter(_.isTerm))
162
162
163
- def avoidPrivateLeaks (sym : Symbol )(implicit ctx : Context ): Type =
163
+ def avoidPrivateLeaks (sym : Symbol )(using Context ): Type =
164
164
if sym.owner.isClass && ! sym.isOneOf(JavaOrPrivateOrSynthetic )
165
165
then checkNoPrivateLeaks(sym)
166
166
else sym.info
167
167
168
- private def toRepeated (tree : Tree , from : ClassSymbol )(implicit ctx : Context ): Tree =
168
+ private def toRepeated (tree : Tree , from : ClassSymbol )(using Context ): Tree =
169
169
Typed (tree, TypeTree (tree.tpe.widen.translateParameterized(from, defn.RepeatedParamClass )))
170
170
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 )
172
172
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 )
174
174
175
175
/** 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
177
177
denot match {
178
178
case denot : SymDenotation =>
179
179
denot.exists && ! denot.isAbsent()
@@ -196,7 +196,7 @@ trait TypeAssigner {
196
196
* (2) if the owner of the denotation is a package object, it is assured
197
197
* that the package object shows up as the prefix.
198
198
*/
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 = {
200
200
def test (tpe : Type , firstTry : Boolean ): Type = tpe match {
201
201
case tpe : NamedType =>
202
202
val pre = tpe.prefix
@@ -240,14 +240,14 @@ trait TypeAssigner {
240
240
*
241
241
* @see QualSkolemType, TypeOps#asSeenFrom
242
242
*/
243
- def maybeSkolemizePrefix (qualType : Type , name : Name )(implicit ctx : Context ): Type =
243
+ def maybeSkolemizePrefix (qualType : Type , name : Name )(using Context ): Type =
244
244
if (name.isTermName && ! ctx.isLegalPrefix(qualType))
245
245
QualSkolemType (qualType)
246
246
else
247
247
qualType
248
248
249
249
/** 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 = {
251
251
var qualType = qual1.tpe.widenIfUnstable
252
252
if (! qualType.hasSimpleKind && tree.name != nme.CONSTRUCTOR )
253
253
// constructors are selected on typeconstructor, type arguments are passed afterwards
@@ -300,7 +300,7 @@ trait TypeAssigner {
300
300
/** The type of the selection in `tree`, where `qual1` is the typed qualifier part.
301
301
* The selection type is additionally checked for accessibility.
302
302
*/
303
- def accessibleSelectionType (tree : untpd.RefTree , qual1 : Tree )(implicit ctx : Context ): Type = {
303
+ def accessibleSelectionType (tree : untpd.RefTree , qual1 : Tree )(using Context ): Type = {
304
304
val ownType = selectionType(tree, qual1)
305
305
if (tree.hasAttachment(desugar.SuppressAccessCheck )) ownType
306
306
else ensureAccessible(ownType, qual1.isInstanceOf [Super ], tree.sourcePos)
@@ -311,10 +311,10 @@ trait TypeAssigner {
311
311
* - typed child trees it needs to access to cpmpute that type,
312
312
* - any further information it needs to access to compute that type.
313
313
*/
314
- def assignType (tree : untpd.Ident , tp : Type )(implicit ctx : Context ): Ident =
314
+ def assignType (tree : untpd.Ident , tp : Type )(using Context ): Ident =
315
315
tree.withType(tp)
316
316
317
- def assignType (tree : untpd.Select , qual : Tree )(implicit ctx : Context ): Select = {
317
+ def assignType (tree : untpd.Select , qual : Tree )(using Context ): Select = {
318
318
def qualType = qual.tpe.widen
319
319
def arrayElemType = {
320
320
qualType match {
@@ -344,15 +344,15 @@ trait TypeAssigner {
344
344
/** Normalize type T appearing in a new T by following eta expansions to
345
345
* avoid higher-kinded types.
346
346
*/
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 {
348
348
case TypeApplications .EtaExpansion (tycon) => tycon
349
349
case t => tpt.tpe
350
350
}
351
351
352
- def assignType (tree : untpd.New , tpt : Tree )(implicit ctx : Context ): New =
352
+ def assignType (tree : untpd.New , tpt : Tree )(using Context ): New =
353
353
tree.withType(typeOfNew(tpt))
354
354
355
- def assignType (tree : untpd.Literal )(implicit ctx : Context ): Literal =
355
+ def assignType (tree : untpd.Literal )(using Context ): Literal =
356
356
tree.withType {
357
357
val value = tree.const
358
358
value.tag match {
@@ -362,14 +362,14 @@ trait TypeAssigner {
362
362
}
363
363
}
364
364
365
- def assignType (tree : untpd.This )(implicit ctx : Context ): This = {
365
+ def assignType (tree : untpd.This )(using Context ): This = {
366
366
val cls = qualifyingClass(tree, tree.qual.name, packageOK = false )
367
367
tree.withType(
368
368
if (cls.isClass) cls.thisType
369
369
else errorType(" not a legal qualifying class for this" , tree.sourcePos))
370
370
}
371
371
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 = {
373
373
val mix = tree.mix
374
374
qual.tpe match {
375
375
case err : ErrorType => untpd.cpy.Super (tree)(qual, mix).withType(err)
@@ -398,7 +398,7 @@ trait TypeAssigner {
398
398
/** Substitute argument type `argType` for parameter `pref` in type `tp`,
399
399
* skolemizing the argument type if it is not stable and `pref` occurs in `tp`.
400
400
*/
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 = {
402
402
val tp1 = tp.substParam(pref, argType)
403
403
if ((tp1 eq tp) || argType.isStable) tp1
404
404
else tp.substParam(pref, SkolemType (argType.widen))
@@ -408,15 +408,15 @@ trait TypeAssigner {
408
408
* The number of parameters `params` may exceed the number of arguments.
409
409
* In this case, only the common prefix is substituted.
410
410
*/
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 {
412
412
case argType :: argTypes1 =>
413
413
val tp1 = safeSubstParam(tp, params.head, argType)
414
414
safeSubstParams(tp1, params.tail, argTypes1)
415
415
case Nil =>
416
416
tp
417
417
}
418
418
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 = {
420
420
val ownType = fn.tpe.widen match {
421
421
case fntpe : MethodType =>
422
422
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
@@ -431,7 +431,7 @@ trait TypeAssigner {
431
431
ConstFold (tree.withType(ownType))
432
432
}
433
433
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 = {
435
435
def fail = tree.withType(errorType(err.takesNoParamsStr(fn, " type " ), tree.sourcePos))
436
436
fn.tpe.widen match {
437
437
case pt : TypeLambda =>
@@ -502,34 +502,34 @@ trait TypeAssigner {
502
502
}
503
503
}
504
504
505
- def assignType (tree : untpd.Typed , tpt : Tree )(implicit ctx : Context ): Typed =
505
+ def assignType (tree : untpd.Typed , tpt : Tree )(using Context ): Typed =
506
506
tree.withType(tpt.tpe)
507
507
508
- def assignType (tree : untpd.NamedArg , arg : Tree )(implicit ctx : Context ): NamedArg =
508
+ def assignType (tree : untpd.NamedArg , arg : Tree )(using Context ): NamedArg =
509
509
tree.withType(arg.tpe)
510
510
511
- def assignType (tree : untpd.Assign )(implicit ctx : Context ): Assign =
511
+ def assignType (tree : untpd.Assign )(using Context ): Assign =
512
512
tree.withType(defn.UnitType )
513
513
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 =
515
515
tree.withType(avoidingType(expr, stats))
516
516
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 =
518
518
tree.withType(avoidingType(expansion, bindings))
519
519
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 =
521
521
tree.withType(thenp.tpe | elsep.tpe)
522
522
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 =
524
524
tree.withType(
525
525
if (target.isEmpty) meth.tpe.widen.toFunctionType(tree.env.length)
526
526
else target.tpe)
527
527
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 = {
529
529
val ownType =
530
530
if (body.isType) {
531
531
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 {
533
533
case t : Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
534
534
case _ => foldOver(ps, t)
535
535
}
@@ -542,37 +542,37 @@ trait TypeAssigner {
542
542
tree.withType(ownType)
543
543
}
544
544
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 =
546
546
tree.withType(ctx.typeComparer.lub(cases.tpes))
547
547
548
- def assignType (tree : untpd.Labeled )(implicit ctx : Context ): Labeled =
548
+ def assignType (tree : untpd.Labeled )(using Context ): Labeled =
549
549
tree.withType(tree.bind.symbol.info)
550
550
551
- def assignType (tree : untpd.Return )(implicit ctx : Context ): Return =
551
+ def assignType (tree : untpd.Return )(using Context ): Return =
552
552
tree.withType(defn.NothingType )
553
553
554
- def assignType (tree : untpd.WhileDo )(implicit ctx : Context ): WhileDo =
554
+ def assignType (tree : untpd.WhileDo )(using Context ): WhileDo =
555
555
tree.withType(if (tree.cond eq EmptyTree ) defn.NothingType else defn.UnitType )
556
556
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 =
558
558
if (cases.isEmpty) tree.withType(expr.tpe)
559
559
else tree.withType(ctx.typeComparer.lub(expr.tpe :: cases.tpes))
560
560
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 = {
562
562
val ownType = tree match {
563
563
case tree : untpd.JavaSeqLiteral => defn.ArrayOf (elemtpt.tpe)
564
564
case _ => if (ctx.erasedTypes) defn.SeqType else defn.SeqType .appliedTo(elemtpt.tpe)
565
565
}
566
566
tree.withType(ownType)
567
567
}
568
568
569
- def assignType (tree : untpd.SingletonTypeTree , ref : Tree )(implicit ctx : Context ): SingletonTypeTree =
569
+ def assignType (tree : untpd.SingletonTypeTree , ref : Tree )(using Context ): SingletonTypeTree =
570
570
tree.withType(ref.tpe)
571
571
572
572
/** Assign type of RefinedType.
573
573
* Refinements are typed as if they were members of refinement class `refineCls`.
574
574
*/
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 = {
576
576
def addRefinement (parent : Type , refinement : Tree ): Type = {
577
577
val rsym = refinement.symbol
578
578
val rinfo = if (rsym.is(Accessor )) rsym.info.resultType else rsym.info
@@ -584,7 +584,7 @@ trait TypeAssigner {
584
584
tree.withType(RecType .closeOver(rt => refined.substThis(refineCls, rt.recThis)))
585
585
}
586
586
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 = {
588
588
assert(! hasNamedArg(args) || ctx.reporter.errorsReported, tree)
589
589
val tparams = tycon.tpe.typeParams
590
590
val ownType =
@@ -596,52 +596,52 @@ trait TypeAssigner {
596
596
tree.withType(ownType)
597
597
}
598
598
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 =
600
600
tree.withType(HKTypeLambda .fromParams(tparamDefs.map(_.symbol.asType), body.tpe))
601
601
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 = {
603
603
val boundType = if (bound.isEmpty) defn.AnyType else bound.tpe
604
604
tree.withType(MatchType (boundType, scrutinee.tpe, cases.tpes))
605
605
}
606
606
607
- def assignType (tree : untpd.ByNameTypeTree , result : Tree )(implicit ctx : Context ): ByNameTypeTree =
607
+ def assignType (tree : untpd.ByNameTypeTree , result : Tree )(using Context ): ByNameTypeTree =
608
608
tree.withType(ExprType (result.tpe))
609
609
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 =
611
611
tree.withType(
612
612
if ! alias.isEmpty then alias.tpe
613
613
else if lo eq hi then TypeAlias (lo.tpe)
614
614
else TypeBounds (lo.tpe, hi.tpe))
615
615
616
- def assignType (tree : untpd.Bind , sym : Symbol )(implicit ctx : Context ): Bind =
616
+ def assignType (tree : untpd.Bind , sym : Symbol )(using Context ): Bind =
617
617
tree.withType(NamedType (NoPrefix , sym))
618
618
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 =
620
620
tree.withType(ctx.typeComparer.lub(trees.tpes))
621
621
622
- def assignType (tree : untpd.UnApply , proto : Type )(implicit ctx : Context ): UnApply =
622
+ def assignType (tree : untpd.UnApply , proto : Type )(using Context ): UnApply =
623
623
tree.withType(proto)
624
624
625
- def assignType (tree : untpd.ValDef , sym : Symbol )(implicit ctx : Context ): ValDef =
625
+ def assignType (tree : untpd.ValDef , sym : Symbol )(using Context ): ValDef =
626
626
tree.withType(if (sym.exists) assertExists(sym.termRef) else NoType )
627
627
628
- def assignType (tree : untpd.DefDef , sym : Symbol )(implicit ctx : Context ): DefDef =
628
+ def assignType (tree : untpd.DefDef , sym : Symbol )(using Context ): DefDef =
629
629
tree.withType(sym.termRef)
630
630
631
- def assignType (tree : untpd.TypeDef , sym : Symbol )(implicit ctx : Context ): TypeDef =
631
+ def assignType (tree : untpd.TypeDef , sym : Symbol )(using Context ): TypeDef =
632
632
tree.withType(sym.typeRef)
633
633
634
634
def assertExists (tp : Type ): Type = { assert(tp != NoType ); tp }
635
635
636
- def assignType (tree : untpd.Import , sym : Symbol )(implicit ctx : Context ): Import =
636
+ def assignType (tree : untpd.Import , sym : Symbol )(using Context ): Import =
637
637
tree.withType(sym.termRef)
638
638
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 = {
640
640
assert(tree.isType) // annotating a term is done via a Typed node, can't use Annotate directly
641
641
tree.withType(AnnotatedType (arg.tpe, Annotation (annot)))
642
642
}
643
643
644
- def assignType (tree : untpd.PackageDef , pid : Tree )(implicit ctx : Context ): PackageDef =
644
+ def assignType (tree : untpd.PackageDef , pid : Tree )(using Context ): PackageDef =
645
645
tree.withType(pid.symbol.termRef)
646
646
}
647
647
0 commit comments