@@ -187,7 +187,7 @@ object Types {
187187 * from the ThisType of `symd`'s owner.
188188 */
189189 def isArgPrefix (symd : SymDenotation )(implicit ctx : Context ) =
190- Config .newScheme && symd.is(ClassTypeParam ) && {
190+ symd.is(ClassTypeParam ) && {
191191 this match {
192192 case tp : ThisType => tp.cls ne symd.owner
193193 case _ => true
@@ -1743,6 +1743,12 @@ object Types {
17431743 def rebase (arg : Type ) = arg.subst(typeParams, concretized)
17441744
17451745 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+
17461752 val argInfo = args(idx) match {
17471753 case arg : TypeBounds =>
17481754 val v = param.paramVariance
@@ -1878,9 +1884,7 @@ object Types {
18781884 while (tparams.nonEmpty && args.nonEmpty) {
18791885 if (tparams.head.eq(tparam))
18801886 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)
18841888 case arg => arg
18851889 }
18861890 tparams = tparams.tail
@@ -3058,7 +3062,7 @@ object Types {
30583062 final val Provisional : DependencyStatus = 4 // set if dependency status can still change due to type variable instantiations
30593063 }
30603064
3061- // ----- Type application: LambdaParam, AppliedType, TypeArgRef ---------------------
3065+ // ----- Type application: LambdaParam, AppliedType ---------------------
30623066
30633067 /** The parameter of a type lambda */
30643068 case class LambdaParam (tl : TypeLambda , n : Int ) extends ParamInfo {
@@ -3136,70 +3140,6 @@ object Types {
31363140 }
31373141 }
31383142
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-
32033143 // ----- BoundTypes: ParamRef, RecThis ----------------------------------------
32043144
32053145 abstract class BoundType extends CachedProxyType with ValueType {
@@ -3800,13 +3740,7 @@ object Types {
38003740 def apply (tp : Type ): Type
38013741
38023742 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)
38103744 protected def derivedRefinedType (tp : RefinedType , parent : Type , info : Type ): Type =
38113745 tp.derivedRefinedType(parent, tp.refinedName, info)
38123746 protected def derivedRecType (tp : RecType , parent : Type ): Type =
@@ -3819,8 +3753,6 @@ object Types {
38193753 tp.derivedSuperType(thistp, supertp)
38203754 protected def derivedAppliedType (tp : AppliedType , tycon : Type , args : List [Type ]): Type =
38213755 tp.derivedAppliedType(tycon, args)
3822- protected def derivedTypeArgRef (tp : TypeArgRef , prefix : Type ): Type =
3823- tp.derivedTypeArgRef(prefix)
38243756 protected def derivedAndOrType (tp : AndOrType , tp1 : Type , tp2 : Type ): Type =
38253757 tp.derivedAndOrType(tp1, tp2)
38263758 protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ): Type =
@@ -3905,9 +3837,6 @@ object Types {
39053837 }
39063838 mapOverLambda
39073839
3908- case tp @ TypeArgRef (prefix, _, _) =>
3909- derivedTypeArgRef(tp, atVariance(variance max 0 )(this (prefix)))
3910-
39113840 case tp @ SuperType (thistp, supertp) =>
39123841 derivedSuperType(tp, this (thistp), this (supertp))
39133842
@@ -4031,27 +3960,39 @@ object Types {
40313960 /** Try to widen a named type to its info relative to given prefix `pre`, where possible.
40323961 * The possible cases are listed inline in the code.
40333962 */
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+ }
40553996
40563997 /** Derived selection.
40573998 * @pre the (upper bound of) prefix `pre` has a member named `tp.name`.
@@ -4061,21 +4002,7 @@ object Types {
40614002 else pre match {
40624003 case Range (preLo, preHi) =>
40634004 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)
40794006 else tryWiden(tp, preHi)
40804007 forwarded.orElse(
40814008 range(super .derivedSelect(tp, preLo), super .derivedSelect(tp, preHi)))
@@ -4178,14 +4105,6 @@ object Types {
41784105 else range(lower(tp1) | lower(tp2), upper(tp1) | upper(tp2))
41794106 else tp.derivedAndOrType(tp1, tp2)
41804107
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-
41894108 override protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ) =
41904109 underlying match {
41914110 case Range (lo, hi) =>
@@ -4321,9 +4240,6 @@ object Types {
43214240 case tp : SkolemType =>
43224241 this (x, tp.info)
43234242
4324- case tp @ TypeArgRef (prefix, _, _) =>
4325- atVariance(variance max 0 )(this (x, prefix))
4326-
43274243 case SuperType (thistp, supertp) =>
43284244 this (this (x, thistp), supertp)
43294245
0 commit comments