Skip to content

Commit facb334

Browse files
committed
LinkerSpecific: make functionality of ResolveSuper accessible.
Linker needs to resolve super calls before they are rewritten in the tree.
1 parent c864e11 commit facb334

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

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)