Skip to content

Commit d6318df

Browse files
committed
Polishings
1 parent 9c41bf8 commit d6318df

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,22 @@ object Denotations {
468468
preferSym(sym1, sym2) &&
469469
info1.overrides(info2, sym1.matchNullaryLoosely || sym2.matchNullaryLoosely, checkClassInfo = false)
470470

471+
/** `sym1` comes before `sym2` in the ranking
472+
* 1. Non-bridge methods
473+
* 2. non-methods
474+
* 3. bridges
475+
* 4. NoSymbol
476+
*/
477+
def preferMethod(sym1: Symbol, sym2: Symbol): Boolean =
478+
sym1.exists &&
479+
(!sym2.exists
480+
|| sym2.is(Bridge) && !sym1.is(Bridge)
481+
|| sym1.is(Method) && !sym2.is(Method)
482+
|| sym1.info.isErroneous)
483+
471484
def handleDoubleDef: Denotation =
472-
if preferSymSimple(sym1, sym2) then denot1
473-
else if preferSymSimple(sym2, sym1) then denot2
485+
if preferMethod(sym1, sym2) then denot1
486+
else if preferMethod(sym2, sym1) then denot2
474487
else MultiDenotation(denot1, denot2)
475488

476489
if (sym2Accessible && prefer(sym2, sym1, info2, info1)) denot2
@@ -481,15 +494,13 @@ object Denotations {
481494
else if (sym2Accessible && sym1.exists && !sym1Accessible) denot2
482495
else if (isDoubleDef(sym1, sym2)) handleDoubleDef
483496
else
484-
val sym =
485-
if (preferSym(sym2, sym1)) sym2
486-
else sym1
497+
val sym = if preferSym(sym2, sym1) then sym2 else sym1
487498
def jointRef(jointInfo: Type) =
488499
JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor, pre)
489500
try jointRef(infoMeet(info1, info2, sym1, sym2, safeIntersection))
490501
catch case ex: MergeError =>
491-
if preferSymSimple(sym2, sym1) then jointRef(info2)
492-
else if preferSymSimple(sym1, sym2) then jointRef(info1)
502+
if preferMethod(sym2, sym1) then jointRef(info2)
503+
else if preferMethod(sym1, sym2) then jointRef(info1)
493504
else if pre.widen.classSymbol.is(Scala2x) || migrateTo3 then
494505
jointRef(info1)
495506
// follow Scala2 linearization -

0 commit comments

Comments
 (0)