diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Types.scala | 10 | ||||
-rw-r--r-- | tests/run/paramForwarding_separate.check | 6 | ||||
-rw-r--r-- | tests/run/paramForwarding_separate/A_1.scala | 3 | ||||
-rw-r--r-- | tests/run/paramForwarding_separate/B_2.scala | 19 |
4 files changed, 33 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index abc496ec0..6c27e53f6 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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 => @@ -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 @@ -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. * @@ -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 diff --git a/tests/run/paramForwarding_separate.check b/tests/run/paramForwarding_separate.check new file mode 100644 index 000000000..8df0c3100 --- /dev/null +++ b/tests/run/paramForwarding_separate.check @@ -0,0 +1,6 @@ +# Fields in A: +private final int A.member$$local +# Fields in SubA: + +# Fields in B: + diff --git a/tests/run/paramForwarding_separate/A_1.scala b/tests/run/paramForwarding_separate/A_1.scala new file mode 100644 index 000000000..7e01f3ef1 --- /dev/null +++ b/tests/run/paramForwarding_separate/A_1.scala @@ -0,0 +1,3 @@ +class A(val member: Int) + +class SubA(member: Int) extends A(member) diff --git a/tests/run/paramForwarding_separate/B_2.scala b/tests/run/paramForwarding_separate/B_2.scala new file mode 100644 index 000000000..774967101 --- /dev/null +++ b/tests/run/paramForwarding_separate/B_2.scala @@ -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]) + } +} |