Skip to content

Commit 7ec75f3

Browse files
committed
Refine disambiguation logic and add test case.
1 parent b93ffa5 commit 7ec75f3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ object Denotations {
305305
!sym2.derivesFrom(sym1) && precedesIn(pre.baseClasses))
306306
}
307307

308+
/** Similar to SymDenotation#accessBoundary, but without the special cases. */
309+
def accessBoundary(sym: Symbol) =
310+
if (sym.is(Private)) sym.owner
311+
else sym.privateWithin.orElse(
312+
if (sym.is(Protected)) sym.owner.enclosingPackageClass
313+
else defn.RootClass
314+
)
315+
308316
/** Establish a partial order "preference" order between symbols.
309317
* Give preference to `sym1` over `sym2` if one of the following
310318
* conditions holds, in decreasing order of weight:
@@ -324,8 +332,7 @@ object Denotations {
324332
sym1.isAsConcrete(sym2) &&
325333
(!sym2.isAsConcrete(sym1) ||
326334
precedes(sym1.owner, sym2.owner) ||
327-
sym2.accessBoundary(sym2.enclosingPackageClass)
328-
.isProperlyContainedIn(sym1.accessBoundary(sym1.enclosingPackageClass)) ||
335+
accessBoundary(sym2).isProperlyContainedIn(accessBoundary(sym1)) ||
329336
sym1.is(Method) && !sym2.is(Method))
330337

331338
/** Sym preference provided types also override */
@@ -338,7 +345,11 @@ object Denotations {
338345
if (sym1Accessible && prefer(sym1, sym2, info1, info2)) denot1
339346
else if (sym1Accessible && sym2.exists && !sym2Accessible) denot1
340347
else if (sym2Accessible && sym1.exists && !sym1Accessible) denot2
341-
else if (isDoubleDef(sym1, sym2)) doubleDefError(denot1, denot2, pre)
348+
else if (isDoubleDef(sym1, sym2)) {
349+
if (preferSym(sym1, sym2)) denot1
350+
else if (preferSym(sym2, sym1)) denot2
351+
else doubleDefError(denot1, denot2, pre)
352+
}
342353
else {
343354
val sym =
344355
if (!sym1.exists) sym2

tests/run/i1386.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
def main(args: Array[String]) =
3+
assert(new java.util.HashMap[Int, Int]().size == 0)
4+
}

0 commit comments

Comments
 (0)