@@ -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
@@ -1736,6 +1736,12 @@ object Types {
1736
1736
def rebase (arg : Type ) = arg.subst(typeParams, concretized)
1737
1737
1738
1738
val idx = typeParams.indexOf(param)
1739
+
1740
+ assert(args.nonEmpty,
1741
+ i """ bad parameter reference $this at ${ctx.phase}
1742
+ |the parameter is ${param.showLocated} but the prefix $prefix
1743
+ |does not define any corresponding arguments. """
1744
+
1739
1745
val argInfo = args(idx) match {
1740
1746
case arg : TypeBounds =>
1741
1747
val v = param.paramVariance
@@ -1871,9 +1877,7 @@ object Types {
1871
1877
while (tparams.nonEmpty && args.nonEmpty) {
1872
1878
if (tparams.head.eq(tparam))
1873
1879
return args.head match {
1874
- case _ : TypeBounds =>
1875
- if (Config .newScheme) TypeRef (pre, tparam)
1876
- else TypeArgRef (pre, cls.typeRef, idx)
1880
+ case _ : TypeBounds => TypeRef (pre, tparam)
1877
1881
case arg => arg
1878
1882
}
1879
1883
tparams = tparams.tail
@@ -3039,7 +3043,7 @@ object Types {
3039
3043
final val Provisional : DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
3040
3044
}
3041
3045
3042
- // ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3046
+ // ----- Type application: LambdaParam, AppliedType ---------------------
3043
3047
3044
3048
/** The parameter of a type lambda */
3045
3049
case class LambdaParam (tl : TypeLambda , n : Int ) extends ParamInfo {
@@ -3117,70 +3121,6 @@ object Types {
3117
3121
}
3118
3122
}
3119
3123
3120
- /** A reference to wildcard argument `p.<parameter X of class C>`
3121
- * where `p: C[... _ ...]`
3122
- */
3123
- abstract case class TypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends CachedProxyType with ValueType {
3124
- assert(prefix.isInstanceOf [ValueType ])
3125
- assert(idx >= 0 )
3126
-
3127
- private [this ] var underlyingCache : Type = _
3128
- private [this ] var underlyingCachePeriod = Nowhere
3129
-
3130
- def computeUnderlying (implicit ctx : Context ): Type = {
3131
- val cls = clsRef.symbol
3132
- val args = prefix.baseType(cls).argInfos
3133
- val typeParams = cls.typeParams
3134
-
3135
- val concretized = TypeArgRef .concretizeArgs(args, prefix, clsRef)
3136
- def rebase (arg : Type ) = arg.subst(typeParams, concretized)
3137
-
3138
- val arg = args(idx)
3139
- val tparam = typeParams(idx)
3140
- val v = tparam.paramVariance
3141
- val pbounds = tparam.paramInfo
3142
- if (v > 0 && pbounds.loBound.dealias.isBottomType) arg.hiBound & rebase(pbounds.hiBound)
3143
- else if (v < 0 && pbounds.hiBound.dealias.isTopType) arg.loBound | rebase(pbounds.loBound)
3144
- else arg recoverable_& rebase(pbounds)
3145
- }
3146
-
3147
- override def underlying (implicit ctx : Context ): Type = {
3148
- if (! ctx.hasSameBaseTypesAs(underlyingCachePeriod)) {
3149
- underlyingCache = computeUnderlying
3150
- underlyingCachePeriod = ctx.period
3151
- }
3152
- underlyingCache
3153
- }
3154
-
3155
- def derivedTypeArgRef (prefix : Type )(implicit ctx : Context ): Type =
3156
- if (prefix eq this .prefix) this else TypeArgRef (prefix, clsRef, idx)
3157
- override def computeHash = doHash(idx, prefix, clsRef)
3158
-
3159
- override def eql (that : Type ) = that match {
3160
- case that : TypeArgRef => prefix.eq(that.prefix) && clsRef.eq(that.clsRef) && idx == that.idx
3161
- case _ => false
3162
- }
3163
- }
3164
-
3165
- final class CachedTypeArgRef (prefix : Type , clsRef : TypeRef , idx : Int ) extends TypeArgRef (prefix, clsRef, idx)
3166
-
3167
- object TypeArgRef {
3168
- def apply (prefix : Type , clsRef : TypeRef , idx : Int )(implicit ctx : Context ) =
3169
- unique(new CachedTypeArgRef (prefix, clsRef, idx))
3170
- def fromParam (prefix : Type , tparam : TypeSymbol )(implicit ctx : Context ) = {
3171
- val cls = tparam.owner
3172
- apply(prefix, cls.typeRef, cls.typeParams.indexOf(tparam))
3173
- }
3174
-
3175
- def concretizeArgs (args : List [Type ], prefix : Type , clsRef : TypeRef )(implicit ctx : Context ): List [Type ] = {
3176
- def concretize (arg : Type , j : Int ) = arg match {
3177
- case arg : TypeBounds => TypeArgRef (prefix, clsRef, j)
3178
- case arg => arg
3179
- }
3180
- args.zipWithConserve(args.indices.toList)(concretize)
3181
- }
3182
- }
3183
-
3184
3124
// ----- BoundTypes: ParamRef, RecThis ----------------------------------------
3185
3125
3186
3126
abstract class BoundType extends CachedProxyType with ValueType {
@@ -3781,13 +3721,7 @@ object Types {
3781
3721
def apply (tp : Type ): Type
3782
3722
3783
3723
protected def derivedSelect (tp : NamedType , pre : Type ): Type =
3784
- tp.derivedSelect(pre) match {
3785
- case tp : TypeArgRef if variance != 0 =>
3786
- val tp1 = tp.underlying
3787
- if (variance > 0 ) tp1.hiBound else tp1.loBound
3788
- case tp =>
3789
- tp
3790
- }
3724
+ tp.derivedSelect(pre)
3791
3725
protected def derivedRefinedType (tp : RefinedType , parent : Type , info : Type ): Type =
3792
3726
tp.derivedRefinedType(parent, tp.refinedName, info)
3793
3727
protected def derivedRecType (tp : RecType , parent : Type ): Type =
@@ -3800,8 +3734,6 @@ object Types {
3800
3734
tp.derivedSuperType(thistp, supertp)
3801
3735
protected def derivedAppliedType (tp : AppliedType , tycon : Type , args : List [Type ]): Type =
3802
3736
tp.derivedAppliedType(tycon, args)
3803
- protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
3804
- tp.derivedTypeArgRef(prefix)
3805
3737
protected def derivedAndOrType (tp : AndOrType , tp1 : Type , tp2 : Type ): Type =
3806
3738
tp.derivedAndOrType(tp1, tp2)
3807
3739
protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ): Type =
@@ -3886,9 +3818,6 @@ object Types {
3886
3818
}
3887
3819
mapOverLambda
3888
3820
3889
- case tp @ TypeArgRef (prefix, _, _) =>
3890
- derivedTypeArgRef(tp, atVariance(variance max 0 )(this (prefix)))
3891
-
3892
3821
case tp @ SuperType (thistp, supertp) =>
3893
3822
derivedSuperType(tp, this (thistp), this (supertp))
3894
3823
@@ -4012,27 +3941,39 @@ object Types {
4012
3941
/** Try to widen a named type to its info relative to given prefix `pre`, where possible.
4013
3942
* The possible cases are listed inline in the code.
4014
3943
*/
4015
- def tryWiden (tp : NamedType , pre : Type ): Type =
4016
- pre.member(tp.name) match {
4017
- case d : SingleDenotation =>
4018
- d.info match {
4019
- case TypeAlias (alias) =>
4020
- // if H#T = U, then for any x in L..H, x.T =:= U,
4021
- // hence we can replace with U under all variances
4022
- reapply(alias)
4023
- case TypeBounds (lo, hi) =>
4024
- // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
4025
- // hence we can replace with S..U under all variances
4026
- range(atVariance(- variance)(reapply(lo)), reapply(hi))
4027
- case info : SingletonType =>
4028
- // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
4029
- // hence we can replace with y.type under all variances
4030
- reapply(info)
4031
- case _ =>
4032
- NoType
4033
- }
4034
- case _ => NoType
4035
- }
3944
+ def tryWiden (tp : NamedType , pre : Type ): Type = pre.member(tp.name) match {
3945
+ case d : SingleDenotation =>
3946
+ d.info match {
3947
+ case TypeAlias (alias) =>
3948
+ // if H#T = U, then for any x in L..H, x.T =:= U,
3949
+ // hence we can replace with U under all variances
3950
+ reapply(alias)
3951
+ case TypeBounds (lo, hi) =>
3952
+ // If H#T = _ >: S <: U, then for any x in L..H, S <: x.T <: U,
3953
+ // hence we can replace with S..U under all variances
3954
+ range(atVariance(- variance)(reapply(lo)), reapply(hi))
3955
+ case info : SingletonType =>
3956
+ // if H#x: y.type, then for any x in L..H, x.type =:= y.type,
3957
+ // hence we can replace with y.type under all variances
3958
+ reapply(info)
3959
+ case _ =>
3960
+ NoType
3961
+ }
3962
+ case _ => NoType
3963
+ }
3964
+
3965
+ /** Expand parameter reference corresponding to prefix `pre`;
3966
+ * If the expansion is a wildcard parameter reference, convert its
3967
+ * underlying bounds to a range, otherwise return the expansion.
3968
+ */
3969
+ def expandParam (tp : NamedType , pre : Type ) = tp.argForParam(pre) match {
3970
+ case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
3971
+ arg.info match {
3972
+ case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
3973
+ case arg => reapply(arg)
3974
+ }
3975
+ case arg => reapply(arg)
3976
+ }
4036
3977
4037
3978
/** Derived selection.
4038
3979
* @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4042,21 +3983,7 @@ object Types {
4042
3983
else pre match {
4043
3984
case Range (preLo, preHi) =>
4044
3985
val forwarded =
4045
- if (tp.symbol.is(ClassTypeParam )) {
4046
- tp.argForParam(preHi) match {
4047
- case arg : TypeArgRef =>
4048
- arg.underlying match {
4049
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4050
- case arg => reapply(arg)
4051
- }
4052
- case arg @ TypeRef (pre, _) if pre.isArgPrefix(arg.symbol) =>
4053
- arg.info match {
4054
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4055
- case arg => reapply(arg)
4056
- }
4057
- case arg => reapply(arg)
4058
- }
4059
- }
3986
+ if (tp.symbol.is(ClassTypeParam )) expandParam(tp, preHi)
4060
3987
else tryWiden(tp, preHi)
4061
3988
forwarded.orElse(
4062
3989
range(super .derivedSelect(tp, preLo), super .derivedSelect(tp, preHi)))
@@ -4159,14 +4086,6 @@ object Types {
4159
4086
else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
4160
4087
else tp.derivedAndOrType(tp1, tp2)
4161
4088
4162
- override protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
4163
- if (isRange(prefix)) // TODO: explain
4164
- tp.underlying match {
4165
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4166
- case _ => range(tp.bottomType, tp.topType)
4167
- }
4168
- else tp.derivedTypeArgRef(prefix)
4169
-
4170
4089
override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
4171
4090
underlying match {
4172
4091
case Range (lo, hi) =>
@@ -4302,9 +4221,6 @@ object Types {
4302
4221
case tp : SkolemType =>
4303
4222
this (x, tp.info)
4304
4223
4305
- case tp @ TypeArgRef (prefix, _, _) =>
4306
- atVariance(variance max 0 )(this (x, prefix))
4307
-
4308
4224
case SuperType (thistp, supertp) =>
4309
4225
this (this (x, thistp), supertp)
4310
4226
0 commit comments