@@ -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
@@ -1742,6 +1742,12 @@ object Types {
1742
1742
def rebase (arg : Type ) = arg.subst(typeParams, concretized)
1743
1743
1744
1744
val idx = typeParams.indexOf(param)
1745
+
1746
+ assert(args.nonEmpty,
1747
+ i """ bad parameter reference $this at ${ctx.phase}
1748
+ |the parameter is ${param.showLocated} but the prefix $prefix
1749
+ |does not define any corresponding arguments. """
1750
+
1745
1751
val argInfo = args(idx) match {
1746
1752
case arg : TypeBounds =>
1747
1753
val v = param.paramVariance
@@ -1877,9 +1883,7 @@ object Types {
1877
1883
while (tparams.nonEmpty && args.nonEmpty) {
1878
1884
if (tparams.head.eq(tparam))
1879
1885
return args.head match {
1880
- case _ : TypeBounds =>
1881
- if (Config .newScheme) TypeRef (pre, tparam)
1882
- else TypeArgRef (pre, cls.typeRef, idx)
1886
+ case _ : TypeBounds => TypeRef (pre, tparam)
1883
1887
case arg => arg
1884
1888
}
1885
1889
tparams = tparams.tail
@@ -3045,7 +3049,7 @@ object Types {
3045
3049
final val Provisional : DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
3046
3050
}
3047
3051
3048
- // ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3052
+ // ----- Type application: LambdaParam, AppliedType ---------------------
3049
3053
3050
3054
/** The parameter of a type lambda */
3051
3055
case class LambdaParam (tl : TypeLambda , n : Int ) extends ParamInfo {
@@ -3123,70 +3127,6 @@ object Types {
3123
3127
}
3124
3128
}
3125
3129
3126
- /** A reference to wildcard argument `p.<parameter X of class C>`
3127
- * where `p: C[... _ ...]`
3128
- */
3129
- abstract case class TypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends CachedProxyType with ValueType {
3130
- assert(prefix.isInstanceOf [ValueType ])
3131
- assert(idx >= 0 )
3132
-
3133
- private [this ] var underlyingCache : Type = _
3134
- private [this ] var underlyingCachePeriod = Nowhere
3135
-
3136
- def computeUnderlying (implicit ctx : Context ): Type = {
3137
- val cls = clsRef.symbol
3138
- val args = prefix.baseType(cls).argInfos
3139
- val typeParams = cls.typeParams
3140
-
3141
- val concretized = TypeArgRef .concretizeArgs(args, prefix, clsRef)
3142
- def rebase (arg : Type ) = arg.subst(typeParams, concretized)
3143
-
3144
- val arg = args(idx)
3145
- val tparam = typeParams(idx)
3146
- val v = tparam.paramVariance
3147
- val pbounds = tparam.paramInfo
3148
- if (v > 0 && pbounds.loBound.dealias.isBottomType) arg.hiBound & rebase(pbounds.hiBound)
3149
- else if (v < 0 && pbounds.hiBound.dealias.isTopType) arg.loBound | rebase(pbounds.loBound)
3150
- else arg recoverable_& rebase(pbounds)
3151
- }
3152
-
3153
- override def underlying (implicit ctx : Context ): Type = {
3154
- if (! ctx.hasSameBaseTypesAs(underlyingCachePeriod)) {
3155
- underlyingCache = computeUnderlying
3156
- underlyingCachePeriod = ctx.period
3157
- }
3158
- underlyingCache
3159
- }
3160
-
3161
- def derivedTypeArgRef (prefix : Type )(implicit ctx : Context ): Type =
3162
- if (prefix eq this .prefix) this else TypeArgRef (prefix, clsRef, idx)
3163
- override def computeHash = doHash(idx, prefix, clsRef)
3164
-
3165
- override def eql (that : Type ) = that match {
3166
- case that : TypeArgRef => prefix.eq(that.prefix) && clsRef.eq(that.clsRef) && idx == that.idx
3167
- case _ => false
3168
- }
3169
- }
3170
-
3171
- final class CachedTypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends TypeArgRef (prefix, clsRef, idx)
3172
-
3173
- object TypeArgRef {
3174
- def apply (prefix : Type , clsRef : TypeRef , idx : Int )(implicit ctx : Context ) =
3175
- unique(new CachedTypeArgRef (prefix, clsRef, idx))
3176
- def fromParam (prefix : Type , tparam : TypeSymbol )(implicit ctx : Context ) = {
3177
- val cls = tparam.owner
3178
- apply(prefix, cls.typeRef, cls.typeParams.indexOf(tparam))
3179
- }
3180
-
3181
- def concretizeArgs (args : List [Type ], prefix : Type , clsRef : TypeRef )(implicit ctx : Context ): List [Type ] = {
3182
- def concretize (arg : Type , j : Int ) = arg match {
3183
- case arg : TypeBounds => TypeArgRef (prefix, clsRef, j)
3184
- case arg => arg
3185
- }
3186
- args.zipWithConserve(args.indices.toList)(concretize)
3187
- }
3188
- }
3189
-
3190
3130
// ----- BoundTypes: ParamRef, RecThis ----------------------------------------
3191
3131
3192
3132
abstract class BoundType extends CachedProxyType with ValueType {
@@ -3787,13 +3727,7 @@ object Types {
3787
3727
def apply (tp : Type ): Type
3788
3728
3789
3729
protected def derivedSelect (tp : NamedType , pre : Type ): Type =
3790
- tp.derivedSelect(pre) match {
3791
- case tp : TypeArgRef if variance != 0 =>
3792
- val tp1 = tp.underlying
3793
- if (variance > 0 ) tp1.hiBound else tp1.loBound
3794
- case tp =>
3795
- tp
3796
- }
3730
+ tp.derivedSelect(pre)
3797
3731
protected def derivedRefinedType (tp : RefinedType , parent : Type , info : Type ): Type =
3798
3732
tp.derivedRefinedType(parent, tp.refinedName, info)
3799
3733
protected def derivedRecType (tp : RecType , parent : Type ): Type =
@@ -3806,8 +3740,6 @@ object Types {
3806
3740
tp.derivedSuperType(thistp, supertp)
3807
3741
protected def derivedAppliedType (tp : AppliedType , tycon : Type , args : List [Type ]): Type =
3808
3742
tp.derivedAppliedType(tycon, args)
3809
- protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
3810
- tp.derivedTypeArgRef(prefix)
3811
3743
protected def derivedAndOrType (tp : AndOrType , tp1 : Type , tp2 : Type ): Type =
3812
3744
tp.derivedAndOrType(tp1, tp2)
3813
3745
protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ): Type =
@@ -3892,9 +3824,6 @@ object Types {
3892
3824
}
3893
3825
mapOverLambda
3894
3826
3895
- case tp @ TypeArgRef (prefix, _, _) =>
3896
- derivedTypeArgRef(tp, atVariance(variance max 0 )(this (prefix)))
3897
-
3898
3827
case tp @ SuperType (thistp, supertp) =>
3899
3828
derivedSuperType(tp, this (thistp), this (supertp))
3900
3829
@@ -4018,27 +3947,39 @@ object Types {
4018
3947
/** Try to widen a named type to its info relative to given prefix `pre`, where possible.
4019
3948
* The possible cases are listed inline in the code.
4020
3949
*/
4021
- def tryWiden (tp : NamedType , pre : Type ): Type =
4022
- pre.member(tp.name) match {
4023
- case d : SingleDenotation =>
4024
- d.info match {
4025
- case TypeAlias (alias) =>
4026
- // if H#T = U, then for any x in L..H, x.T =:= U,
4027
- // hence we can replace with U under all variances
4028
- reapply(alias)
4029
- case TypeBounds (lo, hi) =>
4030
- // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
4031
- // hence we can replace with S..U under all variances
4032
- range(atVariance(- variance)(reapply(lo)), reapply(hi))
4033
- case info : SingletonType =>
4034
- // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
4035
- // hence we can replace with y.type under all variances
4036
- reapply(info)
4037
- case _ =>
4038
- NoType
4039
- }
4040
- case _ => NoType
4041
- }
3950
+ def tryWiden (tp : NamedType , pre : Type ): Type = pre.member(tp.name) match {
3951
+ case d : SingleDenotation =>
3952
+ d.info match {
3953
+ case TypeAlias (alias) =>
3954
+ // if H#T = U, then for any x in L..H, x.T =:= U,
3955
+ // hence we can replace with U under all variances
3956
+ reapply(alias)
3957
+ case TypeBounds (lo, hi) =>
3958
+ // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
3959
+ // hence we can replace with S..U under all variances
3960
+ range(atVariance(- variance)(reapply(lo)), reapply(hi))
3961
+ case info : SingletonType =>
3962
+ // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
3963
+ // hence we can replace with y.type under all variances
3964
+ reapply(info)
3965
+ case _ =>
3966
+ NoType
3967
+ }
3968
+ case _ => NoType
3969
+ }
3970
+
3971
+ /** Expand parameter reference corresponding to prefix `pre`;
3972
+ * If the expansion is a wildcard parameter reference, convert its
3973
+ * underlying bounds to a range, otherwise return the expansion.
3974
+ */
3975
+ def expandParam (tp : NamedType , pre : Type ) = tp.argForParam(pre) match {
3976
+ case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
3977
+ arg.info match {
3978
+ case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
3979
+ case arg => reapply(arg)
3980
+ }
3981
+ case arg => reapply(arg)
3982
+ }
4042
3983
4043
3984
/** Derived selection.
4044
3985
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4048,21 +3989,7 @@ object Types {
4048
3989
else pre match {
4049
3990
case Range (preLo, preHi) =>
4050
3991
val forwarded =
4051
- if (tp.symbol.is(ClassTypeParam )) {
4052
- tp.argForParam(preHi) match {
4053
- case arg : TypeArgRef =>
4054
- arg.underlying match {
4055
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4056
- case arg => reapply(arg)
4057
- }
4058
- case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
4059
- arg.info match {
4060
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4061
- case arg => reapply(arg)
4062
- }
4063
- case arg => reapply(arg)
4064
- }
4065
- }
3992
+ if (tp.symbol.is(ClassTypeParam )) expandParam(tp, preHi)
4066
3993
else tryWiden(tp, preHi)
4067
3994
forwarded.orElse(
4068
3995
range(super .derivedSelect(tp, preLo), super .derivedSelect(tp, preHi)))
@@ -4165,14 +4092,6 @@ object Types {
4165
4092
else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
4166
4093
else tp.derivedAndOrType(tp1, tp2)
4167
4094
4168
- override protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
4169
- if (isRange(prefix)) // TODO: explain
4170
- tp.underlying match {
4171
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4172
- case _ => range(tp.bottomType, tp.topType)
4173
- }
4174
- else tp.derivedTypeArgRef(prefix)
4175
-
4176
4095
override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
4177
4096
underlying match {
4178
4097
case Range (lo, hi) =>
@@ -4308,9 +4227,6 @@ object Types {
4308
4227
case tp : SkolemType =>
4309
4228
this (x, tp.info)
4310
4229
4311
- case tp @ TypeArgRef (prefix, _, _) =>
4312
- atVariance(variance max 0 )(this (x, prefix))
4313
-
4314
4230
case SuperType (thistp, supertp) =>
4315
4231
this (this (x, thistp), supertp)
4316
4232
0 commit comments