@@ -50,32 +50,32 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
50
50
51
51
override def treeTransformPhase = thisTransform.next
52
52
53
+ /** Returns the symbol that is accessed by a super-accessor in a mixin composition.
54
+ *
55
+ * @param base The class in which everything is mixed together
56
+ * @param member The symbol statically referred to by the superaccessor in the trait
57
+ */
58
+ private def rebindSuper (base : Symbol , acc : Symbol )(implicit ctx : Context ): Symbol = {
59
+ var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
60
+ var sym : Symbol = NoSymbol
61
+ val SuperAccessorName (memberName) = acc.name: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
62
+ ctx.debuglog(i " starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName" )
63
+ while (bcs.nonEmpty && sym == NoSymbol ) {
64
+ val other = bcs.head.info.nonPrivateDecl(memberName)
65
+ if (ctx.settings.debug.value)
66
+ ctx.log(i " rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred )}" )
67
+ sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
68
+ bcs = bcs.tail
69
+ }
70
+ assert(sym.exists)
71
+ sym
72
+ }
73
+
53
74
override def transformTemplate (impl : Template )(implicit ctx : Context , info : TransformerInfo ) = {
54
75
val cls = impl.symbol.owner.asClass
55
76
val ops = new MixinOps (cls, thisTransform)
56
77
import ops ._
57
78
58
- /** Returns the symbol that is accessed by a super-accessor in a mixin composition.
59
- *
60
- * @param base The class in which everything is mixed together
61
- * @param member The symbol statically referred to by the superaccessor in the trait
62
- */
63
- def rebindSuper (base : Symbol , acc : Symbol ): Symbol = {
64
- var bcs = cls.info.baseClasses.dropWhile(acc.owner != _).tail
65
- var sym : Symbol = NoSymbol
66
- val SuperAccessorName (memberName) = acc.name: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
67
- ctx.debuglog(i " starting rebindsuper from $cls of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName" )
68
- while (bcs.nonEmpty && sym == NoSymbol ) {
69
- val other = bcs.head.info.nonPrivateDecl(memberName)
70
- if (ctx.settings.debug.value)
71
- ctx.log(i " rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred )}" )
72
- sym = other.matchingDenotation(cls.thisType, cls.thisType.memberInfo(acc)).symbol
73
- bcs = bcs.tail
74
- }
75
- assert(sym.exists)
76
- sym
77
- }
78
-
79
79
def superAccessors (mixin : ClassSymbol ): List [Tree ] =
80
80
for (superAcc <- mixin.decls.filter(_ is SuperAccessor ).toList)
81
81
yield polyDefDef(implementation(superAcc.asTerm), forwarder(rebindSuper(cls, superAcc)))
@@ -94,5 +94,18 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
94
94
95
95
cpy.Template (impl)(body = overrides ::: impl.body)
96
96
}
97
+
98
+ override def transformDefDef (ddef : DefDef )(implicit ctx : Context , info : TransformerInfo ) = {
99
+ val meth = ddef.symbol.asTerm
100
+ if (meth.is(SuperAccessor , butNot = Deferred )) {
101
+ assert(ddef.rhs.isEmpty)
102
+ val cls = meth.owner.asClass
103
+ val ops = new MixinOps (cls, thisTransform)
104
+ import ops ._
105
+ polyDefDef(meth, forwarder(rebindSuper(cls, meth)))
106
+ }
107
+ else ddef
108
+ }
109
+
97
110
private val PrivateOrDeferred = Private | Deferred
98
111
}
0 commit comments