Skip to content

Commit 1497796

Browse files
committed
Follow aliases when deskolemizing
Be more aggressive doing this than with lookupRefined in that we compute the member of a projected name, instead of just analyzing the type structurally. Reason: (1) If we do not follow aliases, skolemization will lose information (2) Skolemization is applied rather late, less risk of cyclic references by computing members.
1 parent 5fe26c0 commit 1497796

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.dotc
22
package core
33

4-
import Symbols._, Types._, Contexts._
4+
import Symbols._, Types._, Contexts._, Decorators._
55
import collection.mutable
66

77
/** Methods to add and remove skolemtypes.
@@ -46,7 +46,7 @@ trait Skolemization {
4646
final def deSkolemize(tp: Type): Type = deSkolemize(tp, 1, Set())
4747

4848
private def deSkolemize(tp: Type, variance: Int, seen: Set[SkolemType]): Type =
49-
ctx.traceIndented(s"deskolemize $tp, variance = $variance, seen = $seen = ") {
49+
ctx.traceIndented(i"deskolemize $tp, variance = $variance, seen = $seen = ", show = true) {
5050
def approx(lo: Type = defn.NothingType, hi: Type = defn.AnyType, newSeen: Set[SkolemType] = seen) =
5151
if (variance == 0) NoType
5252
else deSkolemize(if (variance < 0) lo else hi, variance, newSeen)
@@ -59,12 +59,20 @@ trait Skolemization {
5959
if (sym.isStatic) tp
6060
else {
6161
val pre1 = deSkolemize(tp.prefix, variance, seen)
62-
if (pre1.exists && !pre1.isRef(defn.NothingClass)) tp.derivedSelect(pre1)
62+
if (pre1 eq tp.prefix) tp
6363
else {
64-
ctx.log(s"deskolem: $tp: ${tp.info}")
65-
tp.info match {
66-
case TypeBounds(lo, hi) => approx(lo, hi)
67-
case info => approx(defn.NothingType, info)
64+
val d = tp.prefix.member(tp.name)
65+
d.info match {
66+
case TypeAlias(alias) => deSkolemize(alias, variance, seen)
67+
case _ =>
68+
if (pre1.exists && !pre1.isRef(defn.NothingClass)) tp.derivedSelect(pre1)
69+
else {
70+
ctx.log(s"deskolem: $tp: ${tp.info}")
71+
tp.info match {
72+
case TypeBounds(lo, hi) => approx(lo, hi)
73+
case info => approx(defn.NothingType, info)
74+
}
75+
}
6876
}
6977
}
7078
}

0 commit comments

Comments
 (0)