@@ -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))
@@ -958,7 +969,7 @@ object Types {
958
969
959
970
/** Eliminate anonymous classes */
960
971
final def deAnonymize (implicit ctx : Context ): Type = this match {
961
- case tp: TypeRef if tp.symbol.isAnonymousClass =>
972
+ case tp : TypeRef if tp.symbol.isAnonymousClass =>
962
973
tp.symbol.asClass.typeRef.asSeenFrom(tp.prefix, tp.symbol.owner)
963
974
case tp => tp
964
975
}
@@ -970,6 +981,14 @@ object Types {
970
981
case TypeAlias (tp) => tp.dealias(keepAnnots): @ tailrec
971
982
case _ => tp
972
983
}
984
+ case app @ AppliedType (tycon, args) =>
985
+ val tycon1 = tycon.dealias(keepAnnots)
986
+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
987
+ else this
988
+ case app @ HKApply (tycon, args) =>
989
+ val tycon1 = tycon.dealias(keepAnnots)
990
+ if (tycon1 ne tycon) app.superType.dealias(keepAnnots): @ tailrec
991
+ else this
973
992
case tp : TypeVar =>
974
993
val tp1 = tp.instanceOpt
975
994
if (tp1.exists) tp1.dealias(keepAnnots): @ tailrec else tp
@@ -978,10 +997,6 @@ object Types {
978
997
if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1
979
998
case tp : LazyRef =>
980
999
tp.ref.dealias(keepAnnots): @ tailrec
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
985
1000
case _ => this
986
1001
}
987
1002
@@ -1028,6 +1043,8 @@ object Types {
1028
1043
if (tp.symbol.isClass) tp
1029
1044
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
1030
1045
else NoType
1046
+ case tp : AppliedType =>
1047
+ tp.superType.underlyingClassRef(refinementOK)
1031
1048
case tp : AnnotatedType =>
1032
1049
tp.underlying.underlyingClassRef(refinementOK)
1033
1050
case tp : RefinedType =>
@@ -1165,19 +1182,33 @@ object Types {
1165
1182
* Inherited by all type proxies. Empty for all other types.
1166
1183
* Overwritten in ClassInfo, where parents is cached.
1167
1184
*/
1168
- def parents (implicit ctx : Context ): List [TypeRef ] = this match {
1169
- case tp : TypeProxy => tp.underlying.parents
1170
- case _ => List ()
1185
+ def parentRefs (implicit ctx : Context ): List [TypeRef ] = this match {
1186
+ case tp : TypeProxy => tp.underlying.parentRefs
1187
+ case _ => Nil
1171
1188
}
1172
1189
1173
1190
/** The full parent types, including all type arguments */
1174
1191
def parentsWithArgs (implicit ctx : Context ): List [Type ] = this match {
1175
1192
case tp : TypeProxy => tp.superType.parentsWithArgs
1176
- case _ => List ()
1193
+ case _ => Nil
1194
+ }
1195
+
1196
+ /** The full parent types, including (in new scheme) all type arguments */
1197
+ def parentsNEW (implicit ctx : Context ): List [Type ] = this match {
1198
+ case AppliedType (tycon : HKTypeLambda , args) => // TODO: can be eliminated once ClassInfo is changed, also: cache?
1199
+ tycon.resType.parentsWithArgs.map(_.substParams(tycon, args))
1200
+ case tp : TypeProxy => tp.superType.parentsNEW
1201
+ case _ => Nil
1202
+ }
1203
+
1204
+ /** The first parent of this type, AnyRef if list of parents is empty */
1205
+ def firstParentRef (implicit ctx : Context ): TypeRef = parentRefs match {
1206
+ case p :: _ => p
1207
+ case _ => defn.AnyType
1177
1208
}
1178
1209
1179
1210
/** The first parent of this type, AnyRef if list of parents is empty */
1180
- def firstParent (implicit ctx : Context ): TypeRef = parents match {
1211
+ def firstParentNEW (implicit ctx : Context ): Type = parentsNEW match {
1181
1212
case p :: _ => p
1182
1213
case _ => defn.AnyType
1183
1214
}
@@ -3027,21 +3058,17 @@ object Types {
3027
3058
override def underlying (implicit ctx : Context ): Type = tycon
3028
3059
3029
3060
override def superType (implicit ctx : Context ): Type = {
3030
- def reapply (tp : Type ) = tp match {
3031
- case tp : TypeRef if tp.symbol.isClass => tp
3032
- case _ => tp.applyIfParameterized(args)
3033
- }
3034
3061
if (ctx.period != validSuper) {
3035
3062
validSuper = ctx.period
3036
3063
cachedSuper = tycon match {
3037
3064
case tp : HKTypeLambda => defn.AnyType
3038
3065
case tp : TypeVar if ! tp.inst.exists =>
3039
3066
// supertype not stable, since underlying might change
3040
3067
validSuper = Nowhere
3041
- reapply( tp.underlying)
3068
+ tp.underlying.applyIfParameterized(args )
3042
3069
case tp : TypeProxy =>
3043
3070
if (tp.typeSymbol.is(Provisional )) validSuper = Nowhere
3044
- reapply( tp.superType)
3071
+ tp.superType.applyIfParameterized(args )
3045
3072
case _ => defn.AnyType
3046
3073
}
3047
3074
}
@@ -3448,22 +3475,25 @@ object Types {
3448
3475
private var parentsCache : List [TypeRef ] = null
3449
3476
3450
3477
/** The parent type refs as seen from the given prefix */
3451
- override def parents (implicit ctx : Context ): List [TypeRef ] = {
3478
+ override def parentRefs (implicit ctx : Context ): List [TypeRef ] = {
3452
3479
if (parentsCache == null )
3453
3480
parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf [TypeRef ])
3454
3481
parentsCache
3455
3482
}
3456
3483
3457
3484
/** The parent types with all type arguments */
3458
3485
override def parentsWithArgs (implicit ctx : Context ): List [Type ] =
3459
- parents mapConserve { pref =>
3486
+ parentRefs mapConserve { pref =>
3460
3487
((pref : Type ) /: pref.classSymbol.typeParams) { (parent, tparam) =>
3461
3488
val targSym = decls.lookup(tparam.name)
3462
3489
if (targSym.exists) RefinedType (parent, targSym.name, targSym.info)
3463
3490
else parent
3464
3491
}
3465
3492
}
3466
3493
3494
+ override def parentsNEW (implicit ctx : Context ): List [Type ] =
3495
+ parentRefs // !!! TODO: change
3496
+
3467
3497
def derivedClassInfo (prefix : Type )(implicit ctx : Context ) =
3468
3498
if (prefix eq this .prefix) this
3469
3499
else ClassInfo (prefix, cls, classParents, decls, selfInfo)
@@ -3936,12 +3966,12 @@ object Types {
3936
3966
abstract class DeepTypeMap (implicit ctx : Context ) extends TypeMap {
3937
3967
override def mapClassInfo (tp : ClassInfo ) = {
3938
3968
val prefix1 = this (tp.prefix)
3939
- val parents1 = (tp.parents mapConserve this ).asInstanceOf [List [TypeRef ]]
3969
+ val parentRefs1 = (tp.parentRefs mapConserve this ).asInstanceOf [List [TypeRef ]]
3940
3970
val selfInfo1 = tp.selfInfo match {
3941
3971
case selfInfo : Type => this (selfInfo)
3942
3972
case selfInfo => selfInfo
3943
3973
}
3944
- tp.derivedClassInfo(prefix1, parents1 , tp.decls, selfInfo1)
3974
+ tp.derivedClassInfo(prefix1, parentRefs1 , tp.decls, selfInfo1)
3945
3975
}
3946
3976
}
3947
3977
0 commit comments