@@ -4,6 +4,7 @@ package transform
4
4
import core ._
5
5
import ast .Trees ._
6
6
import Contexts ._ , Types ._ , Symbols ._ , Flags ._ , TypeUtils ._ , DenotTransformers ._ , StdNames ._
7
+ import Names ._ , NameOps ._
7
8
8
9
/** For all parameter accessors
9
10
*
@@ -32,6 +33,8 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
32
33
}
33
34
case _ => (Nil , Nil )
34
35
}
36
+ def findAccessor (cls : Symbol , name : Name ): Symbol =
37
+ cls.info.decl(name).suchThat(_ is (ParamAccessor , butNot = Mutable )).symbol
35
38
def inheritedAccessor (sym : Symbol ): Symbol = {
36
39
/**
37
40
* Dmitry: having it have the same name is needed to maintain correctness in presence of subclassing
@@ -44,9 +47,17 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
44
47
* def s = 3
45
48
* assert(this.b == 2)
46
49
* }
47
- */
48
- val candidate = sym.owner.asClass.superClass
49
- .info.decl(sym.name).suchThat(_ is (ParamAccessor , butNot = (Mutable | Final ))).symbol
50
+ */
51
+ val superCls = sym.owner.asClass.superClass
52
+ val candidate = {
53
+ val candidate0 = findAccessor(superCls, sym.name)
54
+ if (candidate0.exists)
55
+ candidate0
56
+ else
57
+ // If a forwarder was private, it will have been name-mangled by `ensureNotPrivate`
58
+ findAccessor(superCls, sym.name.expandedName(superCls))
59
+ }
60
+
50
61
if (candidate.isAccessibleFrom(currentClass.thisType, superAccess = true )) candidate
51
62
else if (candidate is Method ) inheritedAccessor(candidate)
52
63
else NoSymbol
@@ -63,10 +74,9 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
63
74
val alias = inheritedAccessor(sym)
64
75
if (alias.exists) {
65
76
def forwarder (implicit ctx : Context ) = {
66
- // A private method cannot have the same name as an inherited non-private one,
67
- // so the forwarder should have the same access flags as the alias.
68
- val flags = (sym.flags &~ Private ) | (alias.flags & AccessFlags ) | Override | Method | Stable
77
+ val flags = sym.flags | Method | Stable
69
78
sym.copySymDenotation(initFlags = flags, info = sym.info.ensureMethodic)
79
+ .ensureNotPrivate
70
80
.installAfter(thisTransformer)
71
81
val superAcc =
72
82
Super (This (currentClass), tpnme.EMPTY , inConstrCall = false ).select(alias)
@@ -89,9 +99,10 @@ class ParamForwarding(thisTransformer: DenotTransformer) {
89
99
def adaptRef [T <: RefTree ](tree : T )(implicit ctx : Context ): T = tree.tpe match {
90
100
case tpe : TermRefWithSignature
91
101
if tpe.sig == Signature .NotAMethod && tpe.symbol.is(Method ) =>
92
- // It's a param forwarder; adapt the signature
102
+ // It's a param forwarder; adapt the signature and the name
103
+ val name = tpe.symbol.asTerm.name
93
104
tree.withType(
94
- TermRef .withSig(tpe.prefix, tpe. name, tpe.prefix.memberInfo(tpe.symbol).signature))
105
+ TermRef .withSig(tpe.prefix, name, tpe.prefix.memberInfo(tpe.symbol).signature))
95
106
.asInstanceOf [T ]
96
107
case _ =>
97
108
tree
0 commit comments