@@ -12,19 +12,25 @@ import ast.tpd._
12
12
13
13
trait TypeOps { this : Context => // TODO: Make standalone object.
14
14
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)
16
17
asSeenFrom(tp, pre, cls, null )
17
-
18
+ }
19
+
18
20
final def asSeenFrom (tp : Type , pre : Type , cls : Symbol , theMap : AsSeenFromMap ): Type = {
19
21
20
22
def toPrefix (pre : Type , cls : Symbol , thiscls : ClassSymbol ): Type = /* >|>*/ ctx.conditionalTraceIndented(TypeOps .track, s " toPrefix( $pre, $cls, $thiscls) " ) /* <|<*/ {
21
23
if ((pre eq NoType ) || (pre eq NoPrefix ) || (cls is PackageClass ))
22
24
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
+ }
24
29
pre match {
25
30
case SuperType (thispre, _) => thispre
26
31
case _ => pre
27
32
}
33
+ }
28
34
else if ((pre.termSymbol is Package ) && ! (thiscls is Package ))
29
35
toPrefix(pre.select(nme.PACKAGE ), cls, thiscls)
30
36
else
@@ -36,7 +42,16 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
36
42
case tp : NamedType =>
37
43
val sym = tp.symbol
38
44
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
+ }
40
55
case tp : ThisType =>
41
56
toPrefix(pre, cls, tp.cls)
42
57
case _ : BoundType | NoPrefix =>
@@ -57,6 +72,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
57
72
58
73
class AsSeenFromMap (pre : Type , cls : Symbol ) extends TypeMap {
59
74
def apply (tp : Type ) = asSeenFrom(tp, pre, cls, this )
75
+ def currentVariance = variance
76
+ var unstable = false
60
77
}
61
78
62
79
/** Implementation of Types#simplified */
0 commit comments