Skip to content

Alternative fix for #2099: avoid loading a private member when recomputing a NamedType denot #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ object Types {

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

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

protected def asMemberOf(prefix: Type)(implicit ctx: Context): Denotation =
protected def asMemberOf(prefix: Type, allowPrivate: Boolean)(implicit ctx: Context): Denotation =
if (name.isShadowedName) prefix.nonPrivateMember(name.revertShadowed)
else if (!allowPrivate) prefix.nonPrivateMember(name)
else prefix.member(name)


/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
* to an (unbounded) wildcard type.
*
Expand Down Expand Up @@ -1786,7 +1786,7 @@ object Types {
val candidate = TermRef.withSig(prefix, name, sig)
if (symbol.exists && !candidate.symbol.exists) { // recompute from previous symbol
val ownSym = symbol
val newd = asMemberOf(prefix)
val newd = asMemberOf(prefix, allowPrivate = ownSym.is(Private))
candidate.withDenot(newd.suchThat(_.signature == ownSym.signature))
}
else candidate
Expand Down
6 changes: 6 additions & 0 deletions tests/run/paramForwarding_separate.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fields in A:
private final int A.member$$local
# Fields in SubA:

# Fields in B:

3 changes: 3 additions & 0 deletions tests/run/paramForwarding_separate/A_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A(val member: Int)

class SubA(member: Int) extends A(member)
19 changes: 19 additions & 0 deletions tests/run/paramForwarding_separate/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class B(member: Int) extends SubA(member)

object Test {
def printFields(cls: Class[_]) =
println(cls.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n"))

def main(args: Array[String]): Unit = {
val a = new A(10)
val subA = new SubA(11)
val b = new B(12)

println("# Fields in A:")
printFields(classOf[A])
println("# Fields in SubA:")
printFields(classOf[SubA])
println("# Fields in B:")
printFields(classOf[B])
}
}