@@ -129,9 +129,10 @@ object Types {
129
129
case TypeAlias (tp) =>
130
130
assert((tp ne this ) && (tp ne this1), s " $tp / $this" )
131
131
tp.isRef(sym)
132
- case _ => this1.symbol eq sym
132
+ case _ => this1.symbol eq sym
133
133
}
134
134
case this1 : RefinedOrRecType => this1.parent.isRef(sym)
135
+ case this1 : AppliedType => this1.underlying.isRef(sym)
135
136
case this1 : HKApply => this1.superType.isRef(sym)
136
137
case _ => false
137
138
}
@@ -210,7 +211,7 @@ object Types {
210
211
*/
211
212
private final def phantomLatticeType (implicit ctx : Context ): Type = widen match {
212
213
case tp : ClassInfo if defn.isPhantomTerminalClass(tp.classSymbol) => tp.prefix
213
- case tp : TypeProxy if tp.superType ne this => tp.underlying.phantomLatticeType
214
+ case tp : TypeProxy if tp.superType ne this => tp.underlying.phantomLatticeType // ??? guard needed ???
214
215
case tp : AndOrType => tp.tp1.phantomLatticeType
215
216
case _ => NoType
216
217
}
@@ -483,6 +484,8 @@ object Types {
483
484
})
484
485
case tp : TypeRef =>
485
486
tp.denot.findMember(name, pre, excluded)
487
+ case tp : AppliedType =>
488
+ goApplied(tp)
486
489
case tp : ThisType =>
487
490
goThis(tp)
488
491
case tp : RefinedType =>
@@ -494,7 +497,7 @@ object Types {
494
497
case tp : SuperType =>
495
498
goSuper(tp)
496
499
case tp : HKApply =>
497
- goApply (tp)
500
+ goHKApply (tp)
498
501
case tp : TypeProxy =>
499
502
go(tp.underlying)
500
503
case tp : ClassInfo =>
@@ -584,7 +587,15 @@ object Types {
584
587
}
585
588
}
586
589
587
- def goApply (tp : HKApply ) = tp.tycon match {
590
+ def goApplied (tp : AppliedType ) = tp.tycon match {
591
+ case tl : HKTypeLambda =>
592
+ go(tl.resType).mapInfo(info =>
593
+ tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
594
+ case _ =>
595
+ go(tp.superType)
596
+ }
597
+
598
+ def goHKApply (tp : HKApply ) = tp.tycon match {
588
599
case tl : HKTypeLambda =>
589
600
go(tl.resType).mapInfo(info =>
590
601
tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
@@ -963,6 +974,14 @@ object Types {
963
974
case TypeAlias (tp) => tp.dealias(keepAnnots): @ tailrec
964
975
case _ => tp
965
976
}
977
+ case app @ AppliedType (tycon, args) =>
978
+ val tycon1 = tycon.dealias(keepAnnots)
979
+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
980
+ else this
981
+ case app @ HKApply (tycon, args) =>
982
+ val tycon1 = tycon.dealias(keepAnnots)
983
+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
984
+ else this
966
985
case tp : TypeVar =>
967
986
val tp1 = tp.instanceOpt
968
987
if (tp1.exists) tp1.dealias(keepAnnots): @ tailrec else tp
@@ -971,10 +990,6 @@ object Types {
971
990
if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
972
991
case tp : LazyRef =>
973
992
tp.ref.dealias(keepAnnots): @ tailrec
974
- case app @ HKApply (tycon, args) =>
975
- val tycon1 = tycon.dealias(keepAnnots)
976
- if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
977
- else this
978
993
case _ => this
979
994
}
980
995
@@ -1021,6 +1036,8 @@ object Types {
1021
1036
if (tp.symbol.isClass) tp
1022
1037
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
1023
1038
else NoType
1039
+ case tp : AppliedType =>
1040
+ tp.superType.underlyingClassRef(refinementOK)
1024
1041
case tp : AnnotatedType =>
1025
1042
tp.underlying.underlyingClassRef(refinementOK)
1026
1043
case tp : RefinedType =>
@@ -1158,19 +1175,33 @@ object Types {
1158
1175
* Inherited by all type proxies. Empty for all other types.
1159
1176
* Overwritten in ClassInfo, where parents is cached.
1160
1177
*/
1161
- def parents (implicit ctx : Context ): List [TypeRef ] = this match {
1162
- case tp : TypeProxy => tp.underlying.parents
1163
- case _ => List ()
1178
+ def parentRefs (implicit ctx : Context ): List [TypeRef ] = this match {
1179
+ case tp : TypeProxy => tp.underlying.parentRefs
1180
+ case _ => Nil
1164
1181
}
1165
1182
1166
1183
/** The full parent types, including all type arguments */
1167
1184
def parentsWithArgs (implicit ctx : Context ): List [Type ] = this match {
1168
1185
case tp : TypeProxy => tp.superType.parentsWithArgs
1169
- case _ => List ()
1186
+ case _ => Nil
1187
+ }
1188
+
1189
+ /** The full parent types, including (in new scheme) all type arguments */
1190
+ def parentsNEW (implicit ctx : Context ): List [Type ] = this match {
1191
+ case AppliedType (tycon : HKTypeLambda , args) => // TODO: can be eliminated once ClassInfo is changed, also: cache?
1192
+ tycon.resType.parentsWithArgs.map(_.substParams(tycon, args))
1193
+ case tp : TypeProxy => tp.superType.parentsNEW
1194
+ case _ => Nil
1195
+ }
1196
+
1197
+ /** The first parent of this type, AnyRef if list of parents is empty */
1198
+ def firstParentRef (implicit ctx : Context ): TypeRef = parentRefs match {
1199
+ case p :: _ => p
1200
+ case _ => defn.AnyType
1170
1201
}
1171
1202
1172
1203
/** The first parent of this type, AnyRef if list of parents is empty */
1173
- def firstParent (implicit ctx : Context ): TypeRef = parents match {
1204
+ def firstParentNEW (implicit ctx : Context ): Type = parentsNEW match {
1174
1205
case p :: _ => p
1175
1206
case _ => defn.AnyType
1176
1207
}
@@ -3020,21 +3051,17 @@ object Types {
3020
3051
override def underlying (implicit ctx : Context ): Type = tycon
3021
3052
3022
3053
override def superType (implicit ctx : Context ): Type = {
3023
- def reapply (tp : Type ) = tp match {
3024
- case tp : TypeRef if tp.symbol.isClass => tp
3025
- case _ => tp.applyIfParameterized(args)
3026
- }
3027
3054
if (ctx.period != validSuper) {
3028
3055
validSuper = ctx.period
3029
3056
cachedSuper = tycon match {
3030
3057
case tp : HKTypeLambda => defn.AnyType
3031
3058
case tp : TypeVar if ! tp.inst.exists =>
3032
3059
// supertype not stable, since underlying might change
3033
3060
validSuper = Nowhere
3034
- reapply( tp.underlying)
3061
+ tp.underlying.applyIfParameterized(args )
3035
3062
case tp : TypeProxy =>
3036
3063
if (tp.typeSymbol.is(Provisional )) validSuper = Nowhere
3037
- reapply( tp.superType)
3064
+ tp.superType.applyIfParameterized(args )
3038
3065
case _ => defn.AnyType
3039
3066
}
3040
3067
}
@@ -3441,22 +3468,25 @@ object Types {
3441
3468
private var parentsCache : List [TypeRef ] = null
3442
3469
3443
3470
/** The parent type refs as seen from the given prefix */
3444
- override def parents (implicit ctx : Context ): List [TypeRef ] = {
3471
+ override def parentRefs (implicit ctx : Context ): List [TypeRef ] = {
3445
3472
if (parentsCache == null )
3446
3473
parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf [TypeRef ])
3447
3474
parentsCache
3448
3475
}
3449
3476
3450
3477
/** The parent types with all type arguments */
3451
3478
override def parentsWithArgs (implicit ctx : Context ): List [Type ] =
3452
- parents mapConserve { pref =>
3479
+ parentRefs mapConserve { pref =>
3453
3480
((pref : Type ) /: pref.classSymbol.typeParams) { (parent, tparam) =>
3454
3481
val targSym = decls.lookup(tparam.name)
3455
3482
if (targSym.exists) RefinedType (parent, targSym.name, targSym.info)
3456
3483
else parent
3457
3484
}
3458
3485
}
3459
3486
3487
+ override def parentsNEW (implicit ctx : Context ): List [Type ] =
3488
+ parentRefs // !!! TODO: change
3489
+
3460
3490
def derivedClassInfo (prefix : Type )(implicit ctx : Context ) =
3461
3491
if (prefix eq this .prefix) this
3462
3492
else ClassInfo (prefix, cls, classParents, decls, selfInfo)
@@ -3929,12 +3959,12 @@ object Types {
3929
3959
abstract class DeepTypeMap (implicit ctx : Context ) extends TypeMap {
3930
3960
override def mapClassInfo (tp : ClassInfo ) = {
3931
3961
val prefix1 = this (tp.prefix)
3932
- val parents1 = (tp.parents mapConserve this ).asInstanceOf [List [TypeRef ]]
3962
+ val parentRefs1 = (tp.parentRefs mapConserve this ).asInstanceOf [List [TypeRef ]]
3933
3963
val selfInfo1 = tp.selfInfo match {
3934
3964
case selfInfo : Type => this (selfInfo)
3935
3965
case selfInfo => selfInfo
3936
3966
}
3937
- tp.derivedClassInfo(prefix1, parents1 , tp.decls, selfInfo1)
3967
+ tp.derivedClassInfo(prefix1, parentRefs1 , tp.decls, selfInfo1)
3938
3968
}
3939
3969
}
3940
3970
0 commit comments