From 90c1a5f97db02d4af1a6e05f79285c5229f74702 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 15 Mar 2017 18:21:02 +0100 Subject: Fix #2099: avoid loading a private member when recomputing a NamedType denot ParamForwarding creates the following forwarder in B: private[this] def member: Int = super.member Where the type for `super.member` is `TermRef(SubA, member)` and the symbol is the `val member` in `A`. So far this is correct, but in later phases we might call `loadDenot` on this `TermRef` which will end up calling `asMemberOf`, which before this commit just did: prefix.member(name) This is incorrect in our case because `SubA` also happens to have a private `def member`, which means that our forwarder in B now forwards to a private method in a superclass, this subsequently crashes in `ExpandPrivate`. (Note: in the bytecode, a private method cannot have the same name as an overriden method, but this is already worked around in EnsurePrivate.) The fix is simple: when we recompute a member, we should only look at private members if the previous denotation was private. --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/core/Types.scala') diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index abc496ec0..c88342e12 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1585,8 +1585,12 @@ object Types { protected def asMemberOf(prefix: Type)(implicit ctx: Context): Denotation = if (name.isShadowedName) prefix.nonPrivateMember(name.revertShadowed) - else prefix.member(name) - + else { + val d = lastDenotation + // Never go from a non-private denotation to a private one + if (d == null || d.symbol.is(Private)) prefix.member(name) + else prefix.nonPrivateMember(name) + } /** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type * to an (unbounded) wildcard type. -- cgit v1.2.3