Skip to content

Commit 99a7724

Browse files
committed
Use shadowing to reference inherited accessors.
Normal references won't work since the referenced accessor has the same name as a private name in the class defining the forwarder. This showed up as pickling failures under separate compilation.
1 parent 587a1f4 commit 99a7724

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package transform
44
import core._
55
import ast.Trees._
66
import Contexts._, Types._, Symbols._, Flags._, TypeUtils._, DenotTransformers._, StdNames._
7+
import Decorators._
8+
import config.Printers.typr
79

810
/** For all parameter accessors
911
*
@@ -48,7 +50,7 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
4850
val candidate = sym.owner.asClass.superClass
4951
.info.decl(sym.name).suchThat(_ is (ParamAccessor, butNot = Mutable)).symbol
5052
if (candidate.isAccessibleFrom(currentClass.thisType, superAccess = true)) candidate
51-
else if (candidate is Method) inheritedAccessor(candidate)
53+
else if (candidate.exists) inheritedAccessor(candidate)
5254
else NoSymbol
5355
}
5456
def forwardParamAccessor(stat: Tree): Tree = {
@@ -66,8 +68,12 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
6668
sym.copySymDenotation(initFlags = sym.flags | Method | Stable, info = sym.info.ensureMethodic)
6769
.installAfter(thisTransformer)
6870
val superAcc =
69-
Super(This(currentClass), tpnme.EMPTY, inConstrCall = false).select(alias)
70-
DefDef(sym, superAcc.ensureConforms(sym.info.widen))
71+
Super(This(currentClass), tpnme.EMPTY, inConstrCall = false)
72+
.select(alias)
73+
val stpe @ TermRef(_, _) = superAcc.tpe
74+
val superAccShadowed = superAcc.withType(stpe.shadowed)
75+
typr.println(i"adding param forwarder $superAccShadowed")
76+
DefDef(sym, superAccShadowed.ensureConforms(sym.info.widen))
7177
}
7278
return forwarder(ctx.withPhase(thisTransformer.next))
7379
}

0 commit comments

Comments
 (0)