Skip to content

Commit 2325863

Browse files
authored
Merge pull request #2106 from dotty-staging/fix/param-forwarder-access-take-2
Alternative fix for #2099: avoid loading a private member when recomputing a NamedType denot
2 parents ef55ec0 + ddb8098 commit 2325863

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ object Types {
14821482

14831483
/** A member of `prefix` (disambiguated by `d.signature`) or, if none was found, `d.current`. */
14841484
private def recomputeMember(d: SymDenotation)(implicit ctx: Context): Denotation =
1485-
asMemberOf(prefix) match {
1485+
asMemberOf(prefix, allowPrivate = d.is(Private)) match {
14861486
case NoDenotation => d.current
14871487
case newd: SingleDenotation => newd
14881488
case newd =>
@@ -1573,7 +1573,7 @@ object Types {
15731573
TermRef.withSig(prefix, name.asTermName, sig)
15741574

15751575
protected def loadDenot(implicit ctx: Context): Denotation = {
1576-
val d = asMemberOf(prefix)
1576+
val d = asMemberOf(prefix, allowPrivate = true)
15771577
if (d.exists || ctx.phaseId == FirstPhaseId || !lastDenotation.isInstanceOf[SymDenotation])
15781578
d
15791579
else { // name has changed; try load in earlier phase and make current
@@ -1583,11 +1583,11 @@ object Types {
15831583
}
15841584
}
15851585

1586-
protected def asMemberOf(prefix: Type)(implicit ctx: Context): Denotation =
1586+
protected def asMemberOf(prefix: Type, allowPrivate: Boolean)(implicit ctx: Context): Denotation =
15871587
if (name.isShadowedName) prefix.nonPrivateMember(name.revertShadowed)
1588+
else if (!allowPrivate) prefix.nonPrivateMember(name)
15881589
else prefix.member(name)
15891590

1590-
15911591
/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
15921592
* to an (unbounded) wildcard type.
15931593
*
@@ -1786,7 +1786,7 @@ object Types {
17861786
val candidate = TermRef.withSig(prefix, name, sig)
17871787
if (symbol.exists && !candidate.symbol.exists) { // recompute from previous symbol
17881788
val ownSym = symbol
1789-
val newd = asMemberOf(prefix)
1789+
val newd = asMemberOf(prefix, allowPrivate = ownSym.is(Private))
17901790
candidate.withDenot(newd.suchThat(_.signature == ownSym.signature))
17911791
}
17921792
else candidate
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Fields in A:
2+
private final int A.member$$local
3+
# Fields in SubA:
4+
5+
# Fields in B:
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A(val member: Int)
2+
3+
class SubA(member: Int) extends A(member)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class B(member: Int) extends SubA(member)
2+
3+
object Test {
4+
def printFields(cls: Class[_]) =
5+
println(cls.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n"))
6+
7+
def main(args: Array[String]): Unit = {
8+
val a = new A(10)
9+
val subA = new SubA(11)
10+
val b = new B(12)
11+
12+
println("# Fields in A:")
13+
printFields(classOf[A])
14+
println("# Fields in SubA:")
15+
printFields(classOf[SubA])
16+
println("# Fields in B:")
17+
printFields(classOf[B])
18+
}
19+
}

0 commit comments

Comments
 (0)