Skip to content

Commit 8eeee0b

Browse files
committed
Do prefix comparison only as a final tie breaker
The alternatives with the same symbol could have nevertheless different types. We first want to disambiguate based on these types before we turn to prefixes as a final tie breaker.
1 parent 2e640c2 commit 8eeee0b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+8-9
Original file line numberDiff line numberDiff line change
@@ -1839,11 +1839,7 @@ trait Applications extends Compatibility {
18391839
else -1
18401840

18411841
def compareWithTypes(tp1: Type, tp2: Type) = {
1842-
val ownerScore =
1843-
val sym1 = alt1.symbol
1844-
val sym2 = alt2.symbol
1845-
if sym1 == sym2 then comparePrefixes(widenPrefix(alt1), widenPrefix(alt2))
1846-
else compareOwner(sym1.maybeOwner, sym2.maybeOwner)
1842+
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
18471843

18481844
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
18491845
def winsType2 = isAsSpecific(alt2, tp2, alt1, tp1)
@@ -1874,11 +1870,14 @@ trait Applications extends Compatibility {
18741870
val strippedType2 = stripImplicit(fullType2)
18751871

18761872
val result = compareWithTypes(strippedType1, strippedType2)
1877-
if (result != 0) result
1878-
else if (strippedType1 eq fullType1)
1879-
if (strippedType2 eq fullType2) 0 // no implicits either side: its' a draw
1873+
if result != 0 then result
1874+
else if strippedType1 eq fullType1 then
1875+
if strippedType2 eq fullType2 then
1876+
if alt1.symbol != alt2.symbol then 0 // no implicits either side: it's a draw ...
1877+
else comparePrefixes( // ... unless the symbol is the same, in which case
1878+
widenPrefix(alt1), widenPrefix(alt2)) // we compare prefixes
18801879
else 1 // prefer 1st alternative with no implicits
1881-
else if (strippedType2 eq fullType2) -1 // prefer 2nd alternative with no implicits
1880+
else if strippedType2 eq fullType2 then -1 // prefer 2nd alternative with no implicits
18821881
else compareWithTypes(fullType1, fullType2) // continue by comparing implicits parameters
18831882
}
18841883
end compare

0 commit comments

Comments
 (0)