diff options
author | Dmitry Petrashko <dark@d-d.me> | 2015-09-09 17:00:41 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2015-09-09 17:00:41 +0200 |
commit | 03f860b01b3f7b538925b62609e788884bfdc7ff (patch) | |
tree | 2a65a1fd1c113cfc97a087fce485dda00065c993 /src | |
parent | 15b9a7d22e136f5d29e950102bc1fdd9d6bf8d55 (diff) | |
parent | edee93a70daa0e4ebd2a5390aca629c4d0d2e3d8 (diff) | |
download | dotty-03f860b01b3f7b538925b62609e788884bfdc7ff.tar.gz dotty-03f860b01b3f7b538925b62609e788884bfdc7ff.tar.bz2 dotty-03f860b01b3f7b538925b62609e788884bfdc7ff.zip |
Merge pull request #786 from dotty-staging/fix-#776-param-forwarders
Fix param forwarding
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ExpandPrivate.scala | 38 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 5334bc459..29a31375b 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -828,7 +828,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { val alts = receiver.tpe.member(method).alternatives.map(_.termRef) val alternatives = ctx.typer.resolveOverloaded(alts, proto, Nil) - assert(alternatives.size == 1) // this is parsed from bytecode tree. there's nothing user can do about it + assert(alternatives.size == 1, + i"multiple overloads available for $method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." + + i" isAnnotConstructor = $isAnnotConstructor.\n" + + i"alternatives: $alternatives") // this is parsed from bytecode tree. there's nothing user can do about it val selected = alternatives.head val fun = receiver diff --git a/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/src/dotty/tools/dotc/transform/ExpandPrivate.scala index dfd24290f..110175151 100644 --- a/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -2,6 +2,7 @@ package dotty.tools.dotc package transform import core._ +import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.DenotTransformers.{SymTransformer, IdentityDenotTransformer} import Contexts.Context import Symbols._ @@ -18,12 +19,38 @@ import TreeTransforms._ /** Make private term members that are accessed from another class * non-private by resetting the Private flag and expanding their name. + * + * Also, make non-private any private parameter forwarders that forward to an inherited + * public or protected parameter accessor with the same name as the forwarder. + * This is necessary since private methods are not allowed to have the same name + * as inherited public ones. + * + * See discussion in https://github.com/lampepfl/dotty/pull/784 + * and https://github.com/lampepfl/dotty/issues/783 */ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform => import ast.tpd._ override def phaseName: String = "expandPrivate" + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { + tree match { + case t: DefDef => + val sym = t.symbol + def hasWeakerAccess(other: Symbol) = { + // public > protected > /* default */ > private + if (sym.is(Private)) other.is(Private) + else if (sym.is(Protected)) other.is(Protected | Private) + else true // sym is public + } + val fail = sym.allOverriddenSymbols.findSymbol(x => !hasWeakerAccess(x)) + if (fail.exists) { + assert(false, i"${sym.showFullName} has weaker access that superclass method ${fail.showFullName}") + } + case _ => + } + } + /** Make private terms accessed from different classes non-private. * Note: this happens also for accesses between class and linked module class. * If we change the scheme at one point to make static module class computations @@ -42,4 +69,15 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t ensurePrivateAccessible(tree.symbol) tree } + + override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo) = { + val sym = tree.symbol + tree.rhs match { + case Apply(sel @ Select(_: Super, _), _) + if sym.is(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => + sym.ensureNotPrivate.installAfter(thisTransform) + case _ => + } + tree + } } |