Skip to content

Commit 5cd5cc9

Browse files
committed
new type: TypeRef with a fixed sym and fixed info.
Linker uses it to represent types that normally would never have escaped local scope(and thus have NoPrefix as prefix) that do escape in Linker. Eg, GenTraversableFactory has inner class GenericCanBuildFrom, and anonymous instance of this class in field ReusableCBFInstance. Linker needs to somehow see that the anonymous instance instantiated in List$.ReusableCBFInstance is a subtype of List$.GenTraversableFactory Thus it needs a valid prefix to participate in asSeenFrom and substThis.
1 parent a1a2961 commit 5cd5cc9

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,20 @@ object Types {
16961696
}
16971697

16981698
final class TermRefWithFixedSym(prefix: Type, name: TermName, val fixedSym: TermSymbol) extends TermRef(prefix, name) with WithFixedSym
1699-
final class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym
1699+
class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym
1700+
1701+
/* used by linker */
1702+
final class TypeRefWithFixedSymAndInfo(prefix: Type, name: TypeName, fixedSym: TypeSymbol, val underl: Type) extends TypeRefWithFixedSym(prefix, name, fixedSym) {
1703+
override def derivedSelect(prefix: Type)(implicit ctx: Context): Type =
1704+
if (prefix eq this.prefix) this
1705+
else {
1706+
???
1707+
}
1708+
1709+
override def info(implicit ctx: Context): Type = underl
1710+
1711+
override def equals(that: Any): Boolean = that.isInstanceOf[TypeRefWithFixedSymAndInfo] && super.equals(that) && this.underl == that.asInstanceOf[TypeRefWithFixedSymAndInfo].underl
1712+
}
17001713

17011714
/** Assert current phase does not have erasure semantics */
17021715
private def assertUnerased()(implicit ctx: Context) =
@@ -1817,6 +1830,12 @@ object Types {
18171830
unique(new TypeRefWithFixedSym(prefix, name, sym))
18181831
}
18191832

1833+
def withFixedSymAndInfo(prefix: Type, name: TypeName, sym: TypeSymbol, info: Type)(implicit ctx: Context): TypeRef = {
1834+
if (Config.checkProjections) checkProjection(prefix, name)
1835+
unique(new TypeRefWithFixedSymAndInfo(prefix, name, sym, info))
1836+
}
1837+
1838+
18201839
/** Create a type ref referring to given symbol with given name.
18211840
* This is very similar to TypeRef(Type, Symbol),
18221841
* except for two differences:
@@ -2027,7 +2046,7 @@ object Types {
20272046

20282047
object AndType {
20292048
def apply(tp1: Type, tp2: Type)(implicit ctx: Context) = {
2030-
assert(tp1.isInstanceOf[ValueType] && tp2.isInstanceOf[ValueType])
2049+
assert(tp1.isInstanceOf[ValueType] && tp2.isInstanceOf[ValueType], tp1.show +'\n' + tp2.show)
20312050
unchecked(tp1, tp2)
20322051
}
20332052
def unchecked(tp1: Type, tp2: Type)(implicit ctx: Context) = {
@@ -2658,8 +2677,10 @@ object Types {
26582677
def fullyAppliedRef(implicit ctx: Context): Type = fullyAppliedRef(cls.typeRef, cls.typeParams)
26592678

26602679
def rebase(tp: Type)(implicit ctx: Context): Type =
2661-
if ((prefix eq cls.owner.thisType) || !cls.owner.isClass || ctx.erasedTypes) tp
2662-
else tp.substThis(cls.owner.asClass, prefix)
2680+
if ((prefix eq cls.owner.thisType) || (prefix eq NoPrefix) || ctx.erasedTypes) tp
2681+
else tp.substThis(cls.owner.enclosingClass.asClass, prefix) // enclosingClass is only needed in Linker.
2682+
// for typer originating from typer .owner should always
2683+
// be a class
26632684

26642685
private var typeRefCache: Type = null
26652686

0 commit comments

Comments
 (0)