Skip to content

Commit 9c3782c

Browse files
committed
Track unstability in asSeenFrom
1 parent 4f45784 commit 9c3782c

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@ import ast.tpd._
1212

1313
trait TypeOps { this: Context => // TODO: Make standalone object.
1414

15-
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol): Type =
15+
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol): Type = {
16+
val m = if (pre.isStable || ctx.isAfterTyper) null else new AsSeenFromMap(pre, cls)
1617
asSeenFrom(tp, pre, cls, null)
17-
18+
}
19+
1820
final def asSeenFrom(tp: Type, pre: Type, cls: Symbol, theMap: AsSeenFromMap): Type = {
1921

2022
def toPrefix(pre: Type, cls: Symbol, thiscls: ClassSymbol): Type = /*>|>*/ ctx.conditionalTraceIndented(TypeOps.track, s"toPrefix($pre, $cls, $thiscls)") /*<|<*/ {
2123
if ((pre eq NoType) || (pre eq NoPrefix) || (cls is PackageClass))
2224
tp
23-
else if (thiscls.derivesFrom(cls) && pre.baseTypeRef(thiscls).exists)
25+
else if (thiscls.derivesFrom(cls) && pre.baseTypeRef(thiscls).exists) {
26+
if (!pre.isStable && theMap != null && theMap.currentVariance <= 0) {
27+
theMap.unstable = true
28+
}
2429
pre match {
2530
case SuperType(thispre, _) => thispre
2631
case _ => pre
2732
}
33+
}
2834
else if ((pre.termSymbol is Package) && !(thiscls is Package))
2935
toPrefix(pre.select(nme.PACKAGE), cls, thiscls)
3036
else
@@ -36,7 +42,16 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
3642
case tp: NamedType =>
3743
val sym = tp.symbol
3844
if (sym.isStatic) tp
39-
else tp.derivedSelect(asSeenFrom(tp.prefix, pre, cls, theMap))
45+
else {
46+
val pre1 = asSeenFrom(tp.prefix, pre, cls, theMap)
47+
if (theMap != null && theMap.unstable) {
48+
pre1.member(tp.name).info match {
49+
case TypeAlias(alias) => return alias
50+
case _ =>
51+
}
52+
}
53+
tp.derivedSelect(pre1)
54+
}
4055
case tp: ThisType =>
4156
toPrefix(pre, cls, tp.cls)
4257
case _: BoundType | NoPrefix =>
@@ -57,6 +72,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
5772

5873
class AsSeenFromMap(pre: Type, cls: Symbol) extends TypeMap {
5974
def apply(tp: Type) = asSeenFrom(tp, pre, cls, this)
75+
def currentVariance = variance
76+
var unstable = false
6077
}
6178

6279
/** Implementation of Types#simplified */

0 commit comments

Comments
 (0)