@@ -105,7 +105,7 @@ object Types {
105
105
final def isValueTypeOrLambda : Boolean = isValueType || this .isInstanceOf [PolyType ]
106
106
107
107
/** Does this type denote a stable reference (i.e. singleton type)? */
108
- final def isStable (implicit ctx : Context ): Boolean = stripTypeVar match {
108
+ @ tailrec final def isStable (implicit ctx : Context ): Boolean = stripTypeVar match {
109
109
case tp : TermRef => tp.termSymbol.isStable && tp.prefix.isStable
110
110
case _ : SingletonType | NoPrefix => true
111
111
case tp : RefinedOrRecType => tp.parent.isStable
@@ -188,7 +188,7 @@ object Types {
188
188
final def isErroneous (implicit ctx : Context ): Boolean = existsPart(_.isError, forceLazy = false )
189
189
190
190
/** Does the type carry an annotation that is an instance of `cls`? */
191
- final def hasAnnotation (cls : ClassSymbol )(implicit ctx : Context ): Boolean = stripTypeVar match {
191
+ @ tailrec final def hasAnnotation (cls : ClassSymbol )(implicit ctx : Context ): Boolean = stripTypeVar match {
192
192
case AnnotatedType (tp, annot) => (annot matches cls) || (tp hasAnnotation cls)
193
193
case _ => false
194
194
}
@@ -277,7 +277,7 @@ object Types {
277
277
// ----- Associated symbols ----------------------------------------------
278
278
279
279
/** The type symbol associated with the type */
280
- final def typeSymbol (implicit ctx : Context ): Symbol = this match {
280
+ @ tailrec final def typeSymbol (implicit ctx : Context ): Symbol = this match {
281
281
case tp : TypeRef => tp.symbol
282
282
case tp : ClassInfo => tp.cls
283
283
// case ThisType(cls) => cls // needed?
@@ -292,16 +292,16 @@ object Types {
292
292
*/
293
293
final def classSymbol (implicit ctx : Context ): Symbol = this match {
294
294
case ConstantType (constant) =>
295
- constant.tpe.classSymbol
295
+ constant.tpe.classSymbol: @ tailrec
296
296
case tp : TypeRef =>
297
297
val sym = tp.symbol
298
- if (sym.isClass) sym else tp.superType.classSymbol
298
+ if (sym.isClass) sym else tp.superType.classSymbol: @ tailrec
299
299
case tp : ClassInfo =>
300
300
tp.cls
301
301
case tp : SingletonType =>
302
302
NoSymbol
303
303
case tp : TypeProxy =>
304
- tp.underlying.classSymbol
304
+ tp.underlying.classSymbol: @ tailrec
305
305
case AndType (l, r) =>
306
306
val lsym = l.classSymbol
307
307
val rsym = r.classSymbol
@@ -325,9 +325,9 @@ object Types {
325
325
tp.cls :: Nil
326
326
case tp : TypeRef =>
327
327
val sym = tp.symbol
328
- if (sym.isClass) sym.asClass :: Nil else tp.superType.classSymbols
328
+ if (sym.isClass) sym.asClass :: Nil else tp.superType.classSymbols: @ tailrec
329
329
case tp : TypeProxy =>
330
- tp.underlying.classSymbols
330
+ tp.underlying.classSymbols: @ tailrec
331
331
case AndType (l, r) =>
332
332
l.classSymbols union r.classSymbols
333
333
case OrType (l, r) =>
@@ -337,7 +337,7 @@ object Types {
337
337
}
338
338
339
339
/** The term symbol associated with the type */
340
- final def termSymbol (implicit ctx : Context ): Symbol = this match {
340
+ @ tailrec final def termSymbol (implicit ctx : Context ): Symbol = this match {
341
341
case tp : TermRef => tp.symbol
342
342
case tp : TypeProxy => tp.underlying.termSymbol
343
343
case _ => NoSymbol
@@ -368,11 +368,11 @@ object Types {
368
368
* Defined by ClassInfo, inherited by type proxies.
369
369
* Empty scope for all other types.
370
370
*/
371
- final def decls (implicit ctx : Context ): Scope = this match {
371
+ @ tailrec final def decls (implicit ctx : Context ): Scope = this match {
372
372
case tp : ClassInfo =>
373
373
tp.decls
374
374
case tp : TypeProxy =>
375
- tp.underlying.decls
375
+ tp.underlying.decls: @ tailrec
376
376
case _ =>
377
377
EmptyScope
378
378
}
@@ -394,7 +394,7 @@ object Types {
394
394
* name, as seen from prefix type `pre`. Declarations that have a flag
395
395
* in `excluded` are omitted.
396
396
*/
397
- final def findDecl (name : Name , excluded : FlagSet )(implicit ctx : Context ): Denotation = this match {
397
+ @ tailrec final def findDecl (name : Name , excluded : FlagSet )(implicit ctx : Context ): Denotation = this match {
398
398
case tp : ClassInfo =>
399
399
tp.decls.denotsNamed(name).filterExcluded(excluded).toDenot(NoPrefix )
400
400
case tp : TypeProxy =>
@@ -620,7 +620,7 @@ object Types {
620
620
val ns = tp.parent.memberNames(keepOnly, pre)
621
621
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
622
622
case tp : TypeProxy =>
623
- tp.underlying.memberNames(keepOnly, pre)
623
+ tp.underlying.memberNames(keepOnly, pre): @ tailrec
624
624
case tp : AndType =>
625
625
tp.tp1.memberNames(keepOnly, pre) | tp.tp2.memberNames(keepOnly, pre)
626
626
case tp : OrType =>
@@ -827,23 +827,23 @@ object Types {
827
827
* def o: Outer
828
828
* <o.x.type>.widen = o.C
829
829
*/
830
- final def widen (implicit ctx : Context ): Type = widenSingleton match {
830
+ @ tailrec final def widen (implicit ctx : Context ): Type = widenSingleton match {
831
831
case tp : ExprType => tp.resultType.widen
832
832
case tp => tp
833
833
}
834
834
835
835
/** Widen from singleton type to its underlying non-singleton
836
836
* base type by applying one or more `underlying` dereferences.
837
837
*/
838
- final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar match {
838
+ @ tailrec final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar match {
839
839
case tp : SingletonType if ! tp.isOverloaded => tp.underlying.widenSingleton
840
840
case _ => this
841
841
}
842
842
843
843
/** Widen from TermRef to its underlying non-termref
844
844
* base type, while also skipping Expr types.
845
845
*/
846
- final def widenTermRefExpr (implicit ctx : Context ): Type = stripTypeVar match {
846
+ @ tailrec final def widenTermRefExpr (implicit ctx : Context ): Type = stripTypeVar match {
847
847
case tp : TermRef if ! tp.isOverloaded => tp.underlying.widenExpr.widenTermRefExpr
848
848
case _ => this
849
849
}
@@ -857,7 +857,7 @@ object Types {
857
857
}
858
858
859
859
/** Widen type if it is unstable (i.e. an ExprType, or TermRef to unstable symbol */
860
- final def widenIfUnstable (implicit ctx : Context ): Type = stripTypeVar match {
860
+ @ tailrec final def widenIfUnstable (implicit ctx : Context ): Type = stripTypeVar match {
861
861
case tp : ExprType => tp.resultType.widenIfUnstable
862
862
case tp : TermRef if ! tp.symbol.isStable => tp.underlying.widenIfUnstable
863
863
case _ => this
@@ -880,20 +880,20 @@ object Types {
880
880
case tp : TypeRef =>
881
881
if (tp.symbol.isClass) tp
882
882
else tp.info match {
883
- case TypeAlias (tp) => tp.dealias(keepAnnots)
883
+ case TypeAlias (tp) => tp.dealias(keepAnnots): @ tailrec
884
884
case _ => tp
885
885
}
886
886
case tp : TypeVar =>
887
887
val tp1 = tp.instanceOpt
888
- if (tp1.exists) tp1.dealias(keepAnnots) else tp
888
+ if (tp1.exists) tp1.dealias(keepAnnots): @ tailrec else tp
889
889
case tp : AnnotatedType =>
890
890
val tp1 = tp.tpe.dealias(keepAnnots)
891
891
if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
892
892
case tp : LazyRef =>
893
- tp.ref.dealias(keepAnnots)
893
+ tp.ref.dealias(keepAnnots): @ tailrec
894
894
case app @ HKApply (tycon, args) =>
895
895
val tycon1 = tycon.dealias(keepAnnots)
896
- if (tycon1 ne tycon) app.superType.dealias(keepAnnots)
896
+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
897
897
else this
898
898
case _ => this
899
899
}
@@ -913,7 +913,7 @@ object Types {
913
913
dealias(keepAnnots = false )
914
914
915
915
/** Perform successive widenings and dealiasings until none can be applied anymore */
916
- final def widenDealias (implicit ctx : Context ): Type = {
916
+ @ tailrec final def widenDealias (implicit ctx : Context ): Type = {
917
917
val res = this .widen.dealias
918
918
if (res eq this ) res else res.widenDealias
919
919
}
@@ -996,15 +996,15 @@ object Types {
996
996
* (*) normalizes means: follow instantiated typevars and aliases.
997
997
*/
998
998
def lookupRefined (name : Name )(implicit ctx : Context ): Type = {
999
- def loop (pre : Type ): Type = pre.stripTypeVar match {
999
+ @ tailrec def loop (pre : Type ): Type = pre.stripTypeVar match {
1000
1000
case pre : RefinedType =>
1001
1001
pre.refinedInfo match {
1002
1002
case TypeAlias (alias) =>
1003
1003
if (pre.refinedName ne name) loop(pre.parent) else alias
1004
1004
case _ => loop(pre.parent)
1005
1005
}
1006
1006
case pre : RecType =>
1007
- val candidate = loop( pre.parent)
1007
+ val candidate = pre.parent.lookupRefined(name )
1008
1008
if (candidate.exists && ! pre.isReferredToBy(candidate)) {
1009
1009
// println(s"lookupRefined ${this.toString} . $name, pre: $pre ---> $candidate / ${candidate.toString}")
1010
1010
candidate
@@ -1051,7 +1051,7 @@ object Types {
1051
1051
* Inherited by all other type proxies.
1052
1052
* `NoType` for all other types.
1053
1053
*/
1054
- final def normalizedPrefix (implicit ctx : Context ): Type = this match {
1054
+ @ tailrec final def normalizedPrefix (implicit ctx : Context ): Type = this match {
1055
1055
case tp : NamedType =>
1056
1056
if (tp.symbol.info.isAlias) tp.info.normalizedPrefix else tp.prefix
1057
1057
case tp : ClassInfo =>
@@ -1107,14 +1107,14 @@ object Types {
1107
1107
1108
1108
1109
1109
/** The parameter types in the first parameter section of a generic type or MethodType, Empty list for others */
1110
- final def firstParamTypes (implicit ctx : Context ): List [Type ] = this match {
1110
+ @ tailrec final def firstParamTypes (implicit ctx : Context ): List [Type ] = this match {
1111
1111
case mt : MethodType => mt.paramTypes
1112
1112
case pt : PolyType => pt.resultType.firstParamTypes
1113
1113
case _ => Nil
1114
1114
}
1115
1115
1116
1116
/** Is this either not a method at all, or a parameterless method? */
1117
- final def isParameterless (implicit ctx : Context ): Boolean = this match {
1117
+ @ tailrec final def isParameterless (implicit ctx : Context ): Boolean = this match {
1118
1118
case mt : MethodType => false
1119
1119
case pt : PolyType => pt.resultType.isParameterless
1120
1120
case _ => true
@@ -2101,7 +2101,7 @@ object Types {
2101
2101
}
2102
2102
2103
2103
object RefinedType {
2104
- def make (parent : Type , names : List [Name ], infos : List [Type ])(implicit ctx : Context ): Type =
2104
+ @ tailrec def make (parent : Type , names : List [Name ], infos : List [Type ])(implicit ctx : Context ): Type =
2105
2105
if (names.isEmpty) parent
2106
2106
else make(RefinedType (parent, names.head, infos.head), names.tail, infos.tail)
2107
2107
@@ -3676,7 +3676,7 @@ object Types {
3676
3676
this (x, prefix)
3677
3677
3678
3678
case tp @ HKApply (tycon, args) =>
3679
- def foldArgs (x : T , tparams : List [TypeParamInfo ], args : List [Type ]): T =
3679
+ @ tailrec def foldArgs (x : T , tparams : List [TypeParamInfo ], args : List [Type ]): T =
3680
3680
if (args.isEmpty) {
3681
3681
assert(tparams.isEmpty)
3682
3682
x
@@ -3719,7 +3719,7 @@ object Types {
3719
3719
case _ => x
3720
3720
}
3721
3721
3722
- final def foldOver (x : T , ts : List [Type ]): T = ts match {
3722
+ @ tailrec final def foldOver (x : T , ts : List [Type ]): T = ts match {
3723
3723
case t :: ts1 => foldOver(apply(x, t), ts1)
3724
3724
case nil => x
3725
3725
}
0 commit comments