Skip to content

Commit 03f860b

Browse files
committed
Merge pull request #786 from dotty-staging/fix-#776-param-forwarders
Fix param forwarding
2 parents 15b9a7d + edee93a commit 03f860b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
828828
val alts = receiver.tpe.member(method).alternatives.map(_.termRef)
829829

830830
val alternatives = ctx.typer.resolveOverloaded(alts, proto, Nil)
831-
assert(alternatives.size == 1) // this is parsed from bytecode tree. there's nothing user can do about it
831+
assert(alternatives.size == 1,
832+
i"multiple overloads available for $method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." +
833+
i" isAnnotConstructor = $isAnnotConstructor.\n" +
834+
i"alternatives: $alternatives") // this is parsed from bytecode tree. there's nothing user can do about it
832835

833836
val selected = alternatives.head
834837
val fun = receiver

src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.dotc
22
package transform
33

44
import core._
5+
import dotty.tools.dotc.ast.tpd
56
import dotty.tools.dotc.core.DenotTransformers.{SymTransformer, IdentityDenotTransformer}
67
import Contexts.Context
78
import Symbols._
@@ -18,12 +19,38 @@ import TreeTransforms._
1819

1920
/** Make private term members that are accessed from another class
2021
* non-private by resetting the Private flag and expanding their name.
22+
*
23+
* Also, make non-private any private parameter forwarders that forward to an inherited
24+
* public or protected parameter accessor with the same name as the forwarder.
25+
* This is necessary since private methods are not allowed to have the same name
26+
* as inherited public ones.
27+
*
28+
* See discussion in https://github.com/lampepfl/dotty/pull/784
29+
* and https://github.com/lampepfl/dotty/issues/783
2130
*/
2231
class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
2332
import ast.tpd._
2433

2534
override def phaseName: String = "expandPrivate"
2635

36+
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = {
37+
tree match {
38+
case t: DefDef =>
39+
val sym = t.symbol
40+
def hasWeakerAccess(other: Symbol) = {
41+
// public > protected > /* default */ > private
42+
if (sym.is(Private)) other.is(Private)
43+
else if (sym.is(Protected)) other.is(Protected | Private)
44+
else true // sym is public
45+
}
46+
val fail = sym.allOverriddenSymbols.findSymbol(x => !hasWeakerAccess(x))
47+
if (fail.exists) {
48+
assert(false, i"${sym.showFullName} has weaker access that superclass method ${fail.showFullName}")
49+
}
50+
case _ =>
51+
}
52+
}
53+
2754
/** Make private terms accessed from different classes non-private.
2855
* Note: this happens also for accesses between class and linked module class.
2956
* 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
4269
ensurePrivateAccessible(tree.symbol)
4370
tree
4471
}
72+
73+
override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo) = {
74+
val sym = tree.symbol
75+
tree.rhs match {
76+
case Apply(sel @ Select(_: Super, _), _)
77+
if sym.is(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name =>
78+
sym.ensureNotPrivate.installAfter(thisTransform)
79+
case _ =>
80+
}
81+
tree
82+
}
4583
}

0 commit comments

Comments
 (0)