Skip to content

Commit 66e73e0

Browse files
committed
Merge pull request #1004 from dotty-staging/linker/types
Subtle changes to TypeComarer needed for Linker.
2 parents 705a95f + f9abfd5 commit 66e73e0

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
212212
val cls1 = tp1.cls
213213
cls1.classInfo.selfType.derivesFrom(cls2) &&
214214
cls2.classInfo.selfType.derivesFrom(cls1)
215-
case tp1: TermRef if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
215+
case tp1: NamedType if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
216216
cls2.isStaticOwner ||
217217
isSubType(tp1.prefix, cls2.owner.thisType) ||
218218
secondTry(tp1, tp2)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,9 @@ object Types {
17531753
override def computeHash = unsupported("computeHash")
17541754
}
17551755

1756-
final class TermRefWithFixedSym(prefix: Type, name: TermName, val fixedSym: TermSymbol) extends TermRef(prefix, name) with WithFixedSym
1757-
final class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym
1756+
// Those classes are non final as Linker extends them.
1757+
class TermRefWithFixedSym(prefix: Type, name: TermName, val fixedSym: TermSymbol) extends TermRef(prefix, name) with WithFixedSym
1758+
class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym
17581759

17591760
/** Assert current phase does not have erasure semantics */
17601761
private def assertUnerased()(implicit ctx: Context) =
@@ -1825,6 +1826,10 @@ object Types {
18251826
withFixedSym(prefix, name, sym)
18261827
else if (sym.defRunId != NoRunId && sym.isCompleted)
18271828
withSig(prefix, name, sym.signature) withSym (sym, sym.signature)
1829+
// Linker note:
1830+
// this is problematic, as withSig method could return a hash-consed refference
1831+
// that could have symbol already set making withSym trigger a double-binding error
1832+
// ./tests/run/absoverride.scala demonstates this
18281833
else
18291834
all(prefix, name) withSym (sym, Signature.NotAMethod)
18301835

src/dotty/tools/dotc/transform/ResolveSuper.scala

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ast.Trees._
1717
import util.Positions._
1818
import Names._
1919
import collection.mutable
20+
import ResolveSuper._
2021

2122
/** This phase adds super accessors and method overrides where
2223
* linearization differs from Java's rule for default methods in interfaces.
@@ -51,33 +52,6 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
5152
override def runsAfter = Set(classOf[ElimByName], // verified empirically, need to figure out what the reason is.
5253
classOf[AugmentScala2Traits])
5354

54-
/** Returns the symbol that is accessed by a super-accessor in a mixin composition.
55-
*
56-
* @param base The class in which everything is mixed together
57-
* @param member The symbol statically referred to by the superaccessor in the trait
58-
*/
59-
private def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
60-
var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
61-
var sym: Symbol = NoSymbol
62-
val unexpandedAccName =
63-
if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
64-
acc.name
65-
.drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
66-
.drop(nme.EXPAND_SEPARATOR.length)
67-
else acc.name
68-
val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
69-
ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
70-
while (bcs.nonEmpty && sym == NoSymbol) {
71-
val other = bcs.head.info.nonPrivateDecl(memberName)
72-
if (ctx.settings.debug.value)
73-
ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
74-
sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
75-
bcs = bcs.tail
76-
}
77-
assert(sym.exists)
78-
sym
79-
}
80-
8155
override def transformTemplate(impl: Template)(implicit ctx: Context, info: TransformerInfo) = {
8256
val cls = impl.symbol.owner.asClass
8357
val ops = new MixinOps(cls, thisTransform)
@@ -110,3 +84,32 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
11084

11185
private val PrivateOrAccessorOrDeferred = Private | Accessor | Deferred
11286
}
87+
88+
object ResolveSuper{
89+
/** Returns the symbol that is accessed by a super-accessor in a mixin composition.
90+
*
91+
* @param base The class in which everything is mixed together
92+
* @param acc The symbol statically referred to by the superaccessor in the trait
93+
*/
94+
def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
95+
var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
96+
var sym: Symbol = NoSymbol
97+
val unexpandedAccName =
98+
if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
99+
acc.name
100+
.drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
101+
.drop(nme.EXPAND_SEPARATOR.length)
102+
else acc.name
103+
val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
104+
ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
105+
while (bcs.nonEmpty && sym == NoSymbol) {
106+
val other = bcs.head.info.nonPrivateDecl(memberName)
107+
if (ctx.settings.debug.value)
108+
ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
109+
sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
110+
bcs = bcs.tail
111+
}
112+
assert(sym.exists)
113+
sym
114+
}
115+
}

0 commit comments

Comments
 (0)