@@ -187,7 +187,7 @@ object Types {
187
187
* from the ThisType of `symd`'s owner.
188
188
*/
189
189
def isArgPrefix (symd : SymDenotation )(implicit ctx : Context ) =
190
- Config .newScheme && symd.is(ClassTypeParam ) && {
190
+ symd.is(ClassTypeParam ) && {
191
191
this match {
192
192
case tp : ThisType => tp.cls ne symd.owner
193
193
case _ => true
@@ -1743,6 +1743,12 @@ object Types {
1743
1743
def rebase (arg : Type ) = arg.subst(typeParams, concretized)
1744
1744
1745
1745
val idx = typeParams.indexOf(param)
1746
+
1747
+ assert(args.nonEmpty,
1748
+ i """ bad parameter reference $this at ${ctx.phase}
1749
+ |the parameter is ${param.showLocated} but the prefix $prefix
1750
+ |does not define any corresponding arguments. """
1751
+
1746
1752
val argInfo = args(idx) match {
1747
1753
case arg : TypeBounds =>
1748
1754
val v = param.paramVariance
@@ -1878,9 +1884,7 @@ object Types {
1878
1884
while (tparams.nonEmpty && args.nonEmpty) {
1879
1885
if (tparams.head.eq(tparam))
1880
1886
return args.head match {
1881
- case _ : TypeBounds =>
1882
- if (Config .newScheme) TypeRef (pre, tparam)
1883
- else TypeArgRef (pre, cls.typeRef, idx)
1887
+ case _ : TypeBounds => TypeRef (pre, tparam)
1884
1888
case arg => arg
1885
1889
}
1886
1890
tparams = tparams.tail
@@ -3058,7 +3062,7 @@ object Types {
3058
3062
final val Provisional : DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
3059
3063
}
3060
3064
3061
- // ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3065
+ // ----- Type application: LambdaParam, AppliedType ---------------------
3062
3066
3063
3067
/** The parameter of a type lambda */
3064
3068
case class LambdaParam (tl : TypeLambda , n : Int ) extends ParamInfo {
@@ -3136,70 +3140,6 @@ object Types {
3136
3140
}
3137
3141
}
3138
3142
3139
- /** A reference to wildcard argument `p.<parameter X of class C>`
3140
- * where `p: C[... _ ...]`
3141
- */
3142
- abstract case class TypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends CachedProxyType with ValueType {
3143
- assert(prefix.isInstanceOf [ValueType ])
3144
- assert(idx >= 0 )
3145
-
3146
- private [this ] var underlyingCache : Type = _
3147
- private [this ] var underlyingCachePeriod = Nowhere
3148
-
3149
- def computeUnderlying (implicit ctx : Context ): Type = {
3150
- val cls = clsRef.symbol
3151
- val args = prefix.baseType(cls).argInfos
3152
- val typeParams = cls.typeParams
3153
-
3154
- val concretized = TypeArgRef .concretizeArgs(args, prefix, clsRef)
3155
- def rebase (arg : Type ) = arg.subst(typeParams, concretized)
3156
-
3157
- val arg = args(idx)
3158
- val tparam = typeParams(idx)
3159
- val v = tparam.paramVariance
3160
- val pbounds = tparam.paramInfo
3161
- if (v > 0 && pbounds.loBound.dealias.isBottomType) arg.hiBound & rebase(pbounds.hiBound)
3162
- else if (v < 0 && pbounds.hiBound.dealias.isTopType) arg.loBound | rebase(pbounds.loBound)
3163
- else arg recoverable_& rebase(pbounds)
3164
- }
3165
-
3166
- override def underlying (implicit ctx : Context ): Type = {
3167
- if (! ctx.hasSameBaseTypesAs(underlyingCachePeriod)) {
3168
- underlyingCache = computeUnderlying
3169
- underlyingCachePeriod = ctx.period
3170
- }
3171
- underlyingCache
3172
- }
3173
-
3174
- def derivedTypeArgRef (prefix : Type )(implicit ctx : Context ): Type =
3175
- if (prefix eq this .prefix) this else TypeArgRef (prefix, clsRef, idx)
3176
- override def computeHash = doHash(idx, prefix, clsRef)
3177
-
3178
- override def eql (that : Type ) = that match {
3179
- case that : TypeArgRef => prefix.eq(that.prefix) && clsRef.eq(that.clsRef) && idx == that.idx
3180
- case _ => false
3181
- }
3182
- }
3183
-
3184
- final class CachedTypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends TypeArgRef (prefix, clsRef, idx)
3185
-
3186
- object TypeArgRef {
3187
- def apply (prefix : Type , clsRef : TypeRef , idx : Int )(implicit ctx : Context ) =
3188
- unique(new CachedTypeArgRef (prefix, clsRef, idx))
3189
- def fromParam (prefix : Type , tparam : TypeSymbol )(implicit ctx : Context ) = {
3190
- val cls = tparam.owner
3191
- apply(prefix, cls.typeRef, cls.typeParams.indexOf(tparam))
3192
- }
3193
-
3194
- def concretizeArgs (args : List [Type ], prefix : Type , clsRef : TypeRef )(implicit ctx : Context ): List [Type ] = {
3195
- def concretize (arg : Type , j : Int ) = arg match {
3196
- case arg : TypeBounds => TypeArgRef (prefix, clsRef, j)
3197
- case arg => arg
3198
- }
3199
- args.zipWithConserve(args.indices.toList)(concretize)
3200
- }
3201
- }
3202
-
3203
3143
// ----- BoundTypes: ParamRef, RecThis ----------------------------------------
3204
3144
3205
3145
abstract class BoundType extends CachedProxyType with ValueType {
@@ -3800,13 +3740,7 @@ object Types {
3800
3740
def apply (tp : Type ): Type
3801
3741
3802
3742
protected def derivedSelect (tp : NamedType , pre : Type ): Type =
3803
- tp.derivedSelect(pre) match {
3804
- case tp : TypeArgRef if variance != 0 =>
3805
- val tp1 = tp.underlying
3806
- if (variance > 0 ) tp1.hiBound else tp1.loBound
3807
- case tp =>
3808
- tp
3809
- }
3743
+ tp.derivedSelect(pre)
3810
3744
protected def derivedRefinedType (tp : RefinedType , parent : Type , info : Type ): Type =
3811
3745
tp.derivedRefinedType(parent, tp.refinedName, info)
3812
3746
protected def derivedRecType (tp : RecType , parent : Type ): Type =
@@ -3819,8 +3753,6 @@ object Types {
3819
3753
tp.derivedSuperType(thistp, supertp)
3820
3754
protected def derivedAppliedType (tp : AppliedType , tycon : Type , args : List [Type ]): Type =
3821
3755
tp.derivedAppliedType(tycon, args)
3822
- protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
3823
- tp.derivedTypeArgRef(prefix)
3824
3756
protected def derivedAndOrType (tp : AndOrType , tp1 : Type , tp2 : Type ): Type =
3825
3757
tp.derivedAndOrType(tp1, tp2)
3826
3758
protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ): Type =
@@ -3905,9 +3837,6 @@ object Types {
3905
3837
}
3906
3838
mapOverLambda
3907
3839
3908
- case tp @ TypeArgRef (prefix, _, _) =>
3909
- derivedTypeArgRef(tp, atVariance(variance max 0 )(this (prefix)))
3910
-
3911
3840
case tp @ SuperType (thistp, supertp) =>
3912
3841
derivedSuperType(tp, this (thistp), this (supertp))
3913
3842
@@ -4031,27 +3960,39 @@ object Types {
4031
3960
/** Try to widen a named type to its info relative to given prefix `pre`, where possible.
4032
3961
* The possible cases are listed inline in the code.
4033
3962
*/
4034
- def tryWiden (tp : NamedType , pre : Type ): Type =
4035
- pre.member(tp.name) match {
4036
- case d : SingleDenotation =>
4037
- d.info match {
4038
- case TypeAlias (alias) =>
4039
- // if H#T = U, then for any x in L..H, x.T =:= U,
4040
- // hence we can replace with U under all variances
4041
- reapply(alias)
4042
- case TypeBounds (lo, hi) =>
4043
- // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
4044
- // hence we can replace with S..U under all variances
4045
- range(atVariance(- variance)(reapply(lo)), reapply(hi))
4046
- case info : SingletonType =>
4047
- // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
4048
- // hence we can replace with y.type under all variances
4049
- reapply(info)
4050
- case _ =>
4051
- NoType
4052
- }
4053
- case _ => NoType
4054
- }
3963
+ def tryWiden (tp : NamedType , pre : Type ): Type = pre.member(tp.name) match {
3964
+ case d : SingleDenotation =>
3965
+ d.info match {
3966
+ case TypeAlias (alias) =>
3967
+ // if H#T = U, then for any x in L..H, x.T =:= U,
3968
+ // hence we can replace with U under all variances
3969
+ reapply(alias)
3970
+ case TypeBounds (lo, hi) =>
3971
+ // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
3972
+ // hence we can replace with S..U under all variances
3973
+ range(atVariance(- variance)(reapply(lo)), reapply(hi))
3974
+ case info : SingletonType =>
3975
+ // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
3976
+ // hence we can replace with y.type under all variances
3977
+ reapply(info)
3978
+ case _ =>
3979
+ NoType
3980
+ }
3981
+ case _ => NoType
3982
+ }
3983
+
3984
+ /** Expand parameter reference corresponding to prefix `pre`;
3985
+ * If the expansion is a wildcard parameter reference, convert its
3986
+ * underlying bounds to a range, otherwise return the expansion.
3987
+ */
3988
+ def expandParam (tp : NamedType , pre : Type ) = tp.argForParam(pre) match {
3989
+ case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
3990
+ arg.info match {
3991
+ case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
3992
+ case arg => reapply(arg)
3993
+ }
3994
+ case arg => reapply(arg)
3995
+ }
4055
3996
4056
3997
/** Derived selection.
4057
3998
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4061,21 +4002,7 @@ object Types {
4061
4002
else pre match {
4062
4003
case Range (preLo, preHi) =>
4063
4004
val forwarded =
4064
- if (tp.symbol.is(ClassTypeParam )) {
4065
- tp.argForParam(preHi) match {
4066
- case arg : TypeArgRef =>
4067
- arg.underlying match {
4068
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4069
- case arg => reapply(arg)
4070
- }
4071
- case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
4072
- arg.info match {
4073
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4074
- case arg => reapply(arg)
4075
- }
4076
- case arg => reapply(arg)
4077
- }
4078
- }
4005
+ if (tp.symbol.is(ClassTypeParam )) expandParam(tp, preHi)
4079
4006
else tryWiden(tp, preHi)
4080
4007
forwarded.orElse(
4081
4008
range(super .derivedSelect(tp, preLo), super .derivedSelect(tp, preHi)))
@@ -4178,14 +4105,6 @@ object Types {
4178
4105
else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
4179
4106
else tp.derivedAndOrType(tp1, tp2)
4180
4107
4181
- override protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
4182
- if (isRange(prefix)) // TODO: explain
4183
- tp.underlying match {
4184
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4185
- case _ => range(tp.bottomType, tp.topType)
4186
- }
4187
- else tp.derivedTypeArgRef(prefix)
4188
-
4189
4108
override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
4190
4109
underlying match {
4191
4110
case Range (lo, hi) =>
@@ -4321,9 +4240,6 @@ object Types {
4321
4240
case tp : SkolemType =>
4322
4241
this (x, tp.info)
4323
4242
4324
- case tp @ TypeArgRef (prefix, _, _) =>
4325
- atVariance(variance max 0 )(this (x, prefix))
4326
-
4327
4243
case SuperType (thistp, supertp) =>
4328
4244
this (this (x, thistp), supertp)
4329
4245
0 commit comments