@@ -105,7 +105,7 @@ object Types {
105105 final def isValueTypeOrLambda : Boolean = isValueType || this .isInstanceOf [PolyType ]
106106
107107 /** 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 {
109109 case tp : TermRef => tp.termSymbol.isStable && tp.prefix.isStable
110110 case _ : SingletonType | NoPrefix => true
111111 case tp : RefinedOrRecType => tp.parent.isStable
@@ -188,7 +188,7 @@ object Types {
188188 final def isErroneous (implicit ctx : Context ): Boolean = existsPart(_.isError, forceLazy = false )
189189
190190 /** 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 {
192192 case AnnotatedType (tp, annot) => (annot matches cls) || (tp hasAnnotation cls)
193193 case _ => false
194194 }
@@ -277,7 +277,7 @@ object Types {
277277// ----- Associated symbols ----------------------------------------------
278278
279279 /** 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 {
281281 case tp : TypeRef => tp.symbol
282282 case tp : ClassInfo => tp.cls
283283// case ThisType(cls) => cls // needed?
@@ -292,16 +292,16 @@ object Types {
292292 */
293293 final def classSymbol (implicit ctx : Context ): Symbol = this match {
294294 case ConstantType (constant) =>
295- constant.tpe.classSymbol
295+ constant.tpe.classSymbol: @ tailrec
296296 case tp : TypeRef =>
297297 val sym = tp.symbol
298- if (sym.isClass) sym else tp.superType.classSymbol
298+ if (sym.isClass) sym else tp.superType.classSymbol: @ tailrec
299299 case tp : ClassInfo =>
300300 tp.cls
301301 case tp : SingletonType =>
302302 NoSymbol
303303 case tp : TypeProxy =>
304- tp.underlying.classSymbol
304+ tp.underlying.classSymbol: @ tailrec
305305 case AndType (l, r) =>
306306 val lsym = l.classSymbol
307307 val rsym = r.classSymbol
@@ -325,9 +325,9 @@ object Types {
325325 tp.cls :: Nil
326326 case tp : TypeRef =>
327327 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
329329 case tp : TypeProxy =>
330- tp.underlying.classSymbols
330+ tp.underlying.classSymbols: @ tailrec
331331 case AndType (l, r) =>
332332 l.classSymbols union r.classSymbols
333333 case OrType (l, r) =>
@@ -337,7 +337,7 @@ object Types {
337337 }
338338
339339 /** 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 {
341341 case tp : TermRef => tp.symbol
342342 case tp : TypeProxy => tp.underlying.termSymbol
343343 case _ => NoSymbol
@@ -368,11 +368,11 @@ object Types {
368368 * Defined by ClassInfo, inherited by type proxies.
369369 * Empty scope for all other types.
370370 */
371- final def decls (implicit ctx : Context ): Scope = this match {
371+ @ tailrec final def decls (implicit ctx : Context ): Scope = this match {
372372 case tp : ClassInfo =>
373373 tp.decls
374374 case tp : TypeProxy =>
375- tp.underlying.decls
375+ tp.underlying.decls: @ tailrec
376376 case _ =>
377377 EmptyScope
378378 }
@@ -394,7 +394,7 @@ object Types {
394394 * name, as seen from prefix type `pre`. Declarations that have a flag
395395 * in `excluded` are omitted.
396396 */
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 {
398398 case tp : ClassInfo =>
399399 tp.decls.denotsNamed(name).filterExcluded(excluded).toDenot(NoPrefix )
400400 case tp : TypeProxy =>
@@ -620,7 +620,7 @@ object Types {
620620 val ns = tp.parent.memberNames(keepOnly, pre)
621621 if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
622622 case tp : TypeProxy =>
623- tp.underlying.memberNames(keepOnly, pre)
623+ tp.underlying.memberNames(keepOnly, pre): @ tailrec
624624 case tp : AndType =>
625625 tp.tp1.memberNames(keepOnly, pre) | tp.tp2.memberNames(keepOnly, pre)
626626 case tp : OrType =>
@@ -827,23 +827,23 @@ object Types {
827827 * def o: Outer
828828 * <o.x.type>.widen = o.C
829829 */
830- final def widen (implicit ctx : Context ): Type = widenSingleton match {
830+ @ tailrec final def widen (implicit ctx : Context ): Type = widenSingleton match {
831831 case tp : ExprType => tp.resultType.widen
832832 case tp => tp
833833 }
834834
835835 /** Widen from singleton type to its underlying non-singleton
836836 * base type by applying one or more `underlying` dereferences.
837837 */
838- final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar match {
838+ @ tailrec final def widenSingleton (implicit ctx : Context ): Type = stripTypeVar match {
839839 case tp : SingletonType if ! tp.isOverloaded => tp.underlying.widenSingleton
840840 case _ => this
841841 }
842842
843843 /** Widen from TermRef to its underlying non-termref
844844 * base type, while also skipping Expr types.
845845 */
846- final def widenTermRefExpr (implicit ctx : Context ): Type = stripTypeVar match {
846+ @ tailrec final def widenTermRefExpr (implicit ctx : Context ): Type = stripTypeVar match {
847847 case tp : TermRef if ! tp.isOverloaded => tp.underlying.widenExpr.widenTermRefExpr
848848 case _ => this
849849 }
@@ -857,7 +857,7 @@ object Types {
857857 }
858858
859859 /** 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 {
861861 case tp : ExprType => tp.resultType.widenIfUnstable
862862 case tp : TermRef if ! tp.symbol.isStable => tp.underlying.widenIfUnstable
863863 case _ => this
@@ -880,20 +880,20 @@ object Types {
880880 case tp : TypeRef =>
881881 if (tp.symbol.isClass) tp
882882 else tp.info match {
883- case TypeAlias (tp) => tp.dealias(keepAnnots)
883+ case TypeAlias (tp) => tp.dealias(keepAnnots): @ tailrec
884884 case _ => tp
885885 }
886886 case tp : TypeVar =>
887887 val tp1 = tp.instanceOpt
888- if (tp1.exists) tp1.dealias(keepAnnots) else tp
888+ if (tp1.exists) tp1.dealias(keepAnnots): @ tailrec else tp
889889 case tp : AnnotatedType =>
890890 val tp1 = tp.tpe.dealias(keepAnnots)
891891 if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
892892 case tp : LazyRef =>
893- tp.ref.dealias(keepAnnots)
893+ tp.ref.dealias(keepAnnots): @ tailrec
894894 case app @ HKApply (tycon, args) =>
895895 val tycon1 = tycon.dealias(keepAnnots)
896- if (tycon1 ne tycon) app.superType.dealias(keepAnnots)
896+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
897897 else this
898898 case _ => this
899899 }
@@ -913,7 +913,7 @@ object Types {
913913 dealias(keepAnnots = false )
914914
915915 /** 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 = {
917917 val res = this .widen.dealias
918918 if (res eq this ) res else res.widenDealias
919919 }
@@ -996,15 +996,15 @@ object Types {
996996 * (*) normalizes means: follow instantiated typevars and aliases.
997997 */
998998 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 {
10001000 case pre : RefinedType =>
10011001 pre.refinedInfo match {
10021002 case TypeAlias (alias) =>
10031003 if (pre.refinedName ne name) loop(pre.parent) else alias
10041004 case _ => loop(pre.parent)
10051005 }
10061006 case pre : RecType =>
1007- val candidate = loop( pre.parent)
1007+ val candidate = pre.parent.lookupRefined(name )
10081008 if (candidate.exists && ! pre.isReferredToBy(candidate)) {
10091009 // println(s"lookupRefined ${this.toString} . $name, pre: $pre ---> $candidate / ${candidate.toString}")
10101010 candidate
@@ -1051,7 +1051,7 @@ object Types {
10511051 * Inherited by all other type proxies.
10521052 * `NoType` for all other types.
10531053 */
1054- final def normalizedPrefix (implicit ctx : Context ): Type = this match {
1054+ @ tailrec final def normalizedPrefix (implicit ctx : Context ): Type = this match {
10551055 case tp : NamedType =>
10561056 if (tp.symbol.info.isAlias) tp.info.normalizedPrefix else tp.prefix
10571057 case tp : ClassInfo =>
@@ -1107,14 +1107,14 @@ object Types {
11071107
11081108
11091109 /** 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 {
11111111 case mt : MethodType => mt.paramTypes
11121112 case pt : PolyType => pt.resultType.firstParamTypes
11131113 case _ => Nil
11141114 }
11151115
11161116 /** 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 {
11181118 case mt : MethodType => false
11191119 case pt : PolyType => pt.resultType.isParameterless
11201120 case _ => true
@@ -2101,7 +2101,7 @@ object Types {
21012101 }
21022102
21032103 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 =
21052105 if (names.isEmpty) parent
21062106 else make(RefinedType (parent, names.head, infos.head), names.tail, infos.tail)
21072107
@@ -3676,7 +3676,7 @@ object Types {
36763676 this (x, prefix)
36773677
36783678 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 =
36803680 if (args.isEmpty) {
36813681 assert(tparams.isEmpty)
36823682 x
@@ -3719,7 +3719,7 @@ object Types {
37193719 case _ => x
37203720 }
37213721
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 {
37233723 case t :: ts1 => foldOver(apply(x, t), ts1)
37243724 case nil => x
37253725 }
0 commit comments