@@ -182,6 +182,18 @@ object Types {
182
182
loop(this )
183
183
}
184
184
185
+ /** True iff `symd` is a denotation of a class type parameter and the reference
186
+ * `<this> . <symd>` is an actual argument reference, i.e. `this` is different
187
+ * from the ThisType of `symd`'s owner.
188
+ */
189
+ def isArgPrefix (symd : SymDenotation )(implicit ctx : Context ) =
190
+ Config .newScheme && symd.is(ClassTypeParam ) && {
191
+ this match {
192
+ case tp : ThisType => tp.cls ne symd.owner
193
+ case _ => true
194
+ }
195
+ }
196
+
185
197
/** Returns true if the type is a phantom type
186
198
* - true if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
187
199
* - false otherwise
@@ -1659,6 +1671,8 @@ object Types {
1659
1671
val symd = sym.lastKnownDenotation
1660
1672
if (symd.validFor.runId != ctx.runId && ! ctx.stillValid(symd))
1661
1673
finish(memberDenot(symd.initial.name, allowPrivate = false ))
1674
+ else if (prefix.isArgPrefix(symd))
1675
+ finish(argDenot(sym.asType))
1662
1676
else if (infoDependsOnPrefix(symd, prefix))
1663
1677
finish(memberDenot(symd.initial.name, allowPrivate = symd.is(Private )))
1664
1678
else
@@ -1714,6 +1728,32 @@ object Types {
1714
1728
private def memberDenot (prefix : Type , name : Name , allowPrivate : Boolean )(implicit ctx : Context ): Denotation =
1715
1729
if (allowPrivate) prefix.member(name) else prefix.nonPrivateMember(name)
1716
1730
1731
+ private def argDenot (param : TypeSymbol )(implicit ctx : Context ): Denotation = {
1732
+ val cls = param.owner
1733
+ val args = prefix.baseType(cls).argInfos
1734
+ val typeParams = cls.typeParams
1735
+
1736
+ def concretize (arg : Type , tparam : TypeSymbol ) = arg match {
1737
+ case arg : TypeBounds => TypeRef (prefix, tparam)
1738
+ case arg => arg
1739
+ }
1740
+ val concretized = args.zipWithConserve(typeParams)(concretize)
1741
+
1742
+ def rebase (arg : Type ) = arg.subst(typeParams, concretized)
1743
+
1744
+ val idx = typeParams.indexOf(param)
1745
+ val argInfo = args(idx) match {
1746
+ case arg : TypeBounds =>
1747
+ val v = param.paramVariance
1748
+ val pbounds = param.paramInfo
1749
+ if (v > 0 && pbounds.loBound.dealias.isBottomType) TypeAlias (arg.hiBound & rebase(pbounds.hiBound))
1750
+ else if (v < 0 && pbounds.hiBound.dealias.isTopType) TypeAlias (arg.loBound | rebase(pbounds.loBound))
1751
+ else arg recoverable_& rebase(pbounds)
1752
+ case arg => TypeAlias (arg)
1753
+ }
1754
+ param.derivedSingleDenotation(param, argInfo)
1755
+ }
1756
+
1717
1757
/** Reload denotation by computing the member with the reference's name as seen
1718
1758
* from the reference's prefix.
1719
1759
*/
@@ -1837,7 +1877,9 @@ object Types {
1837
1877
while (tparams.nonEmpty && args.nonEmpty) {
1838
1878
if (tparams.head.eq(tparam))
1839
1879
return args.head match {
1840
- case _ : TypeBounds => TypeArgRef (pre, cls.typeRef, idx)
1880
+ case _ : TypeBounds =>
1881
+ if (Config .newScheme) TypeRef (pre, tparam)
1882
+ else TypeArgRef (pre, cls.typeRef, idx)
1841
1883
case arg => arg
1842
1884
}
1843
1885
tparams = tparams.tail
@@ -1936,7 +1978,7 @@ object Types {
1936
1978
else if (lastDenotation == null ) NamedType (prefix, designator)
1937
1979
else designator match {
1938
1980
case sym : Symbol =>
1939
- if (infoDependsOnPrefix(sym, prefix)) {
1981
+ if (infoDependsOnPrefix(sym, prefix) && ! prefix.isArgPrefix(sym) ) {
1940
1982
val candidate = reload()
1941
1983
val falseOverride = sym.isClass && candidate.symbol.exists && candidate.symbol != symbol
1942
1984
// A false override happens if we rebind an inner class to another type with the same name
@@ -4013,6 +4055,11 @@ object Types {
4013
4055
case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4014
4056
case arg => reapply(arg)
4015
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
+ }
4016
4063
case arg => reapply(arg)
4017
4064
}
4018
4065
}
0 commit comments