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 2 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
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,13 @@ object Types {

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

else lastDenotation match {
case d: SymDenotation if !d.is(Private) =>
// We shouldn't go from a non-private denotation to a private one
prefix.nonPrivateMember(name)
case _ =>
prefix.member(name)
Copy link
Contributor

@odersky odersky Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think we should revert to the previous scheme where allowPrivate was passed as a boolean to asMemberOf. There are 3 calls to asMemberOf. The ones in recomputeDenot and newLikeThis can get the parameter from the symbol. The third one, in loadDenot should unconditionally pass true for
allowPrivate. After all, it could be that a definition was public in run 1, but private in run 2. We need to be able to pick up the new definition in loadDenot.

}

/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
* to an (unbounded) wildcard type.
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])
}
}