Skip to content

Commit 7f37305

Browse files
committed
Drop logic which is now redundant
Since we always prefer inner implicits over outer ones, no need to also consider levels when disambiguating.
1 parent cc832f8 commit 7f37305

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,21 +1181,17 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
11811181
/** Compare to alternatives of an overloaded call or an implicit search.
11821182
*
11831183
* @param alt1, alt2 Non-overloaded references indicating the two choices
1184-
* @param level1, level2 If alternatives come from a comparison of two contextual
1185-
* implicit candidates, the nesting levels of the candidates.
1186-
* In all other cases the nesting levels are both 0.
11871184
* @return 1 if 1st alternative is preferred over 2nd
11881185
* -1 if 2nd alternative is preferred over 1st
11891186
* 0 if neither alternative is preferred over the other
11901187
*
11911188
* An alternative A1 is preferred over an alternative A2 if it wins in a tournament
11921189
* that awards one point for each of the following:
11931190
*
1194-
* - A1 is nested more deeply than A2
1195-
* - The nesting levels of A1 and A2 are the same, and A1's owner derives from A2's owner
1191+
* - A1's owner derives from A2's owner.
11961192
* - A1's type is more specific than A2's type.
11971193
*/
1198-
def compare(alt1: TermRef, alt2: TermRef, nesting1: Int = 0, nesting2: Int = 0)(implicit ctx: Context): Int = track("compare") { trace(i"compare($alt1, $alt2)", overload) {
1194+
def compare(alt1: TermRef, alt2: TermRef)(implicit ctx: Context): Int = track("compare") { trace(i"compare($alt1, $alt2)", overload) {
11991195

12001196
assert(alt1 ne alt2)
12011197

@@ -1305,10 +1301,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
13051301

13061302
val owner1 = if (alt1.symbol.exists) alt1.symbol.owner else NoSymbol
13071303
val owner2 = if (alt2.symbol.exists) alt2.symbol.owner else NoSymbol
1308-
val ownerScore =
1309-
if (nesting1 > nesting2) 1
1310-
else if (nesting1 < nesting2) -1
1311-
else compareOwner(owner1, owner2)
1304+
val ownerScore = compareOwner(owner1, owner2)
13121305

13131306
val tp1 = stripImplicit(alt1.widen)
13141307
val tp2 = stripImplicit(alt2.widen)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,6 @@ trait Implicits { self: Typer =>
987987

988988
private def isCoherent = pt.isRef(defn.EqClass)
989989

990-
private val cmpContext = nestedContext()
991-
private val cmpCandidates = (c1: Candidate, c2: Candidate) => compare(c1.ref, c2.ref, c1.level, c2.level)(cmpContext)
992-
993990
/** The expected type for the searched implicit */
994991
lazy val fullProto: Type = implicitProto(pt, identity)
995992

@@ -1096,13 +1093,14 @@ trait Implicits { self: Typer =>
10961093

10971094
/** Search a list of eligible implicit references */
10981095
def searchImplicits(eligible: List[Candidate], contextual: Boolean): SearchResult = {
1096+
10991097
/** Compare previous success with reference and level to determine which one would be chosen, if
11001098
* an implicit starting with the reference was found.
11011099
*/
11021100
def compareCandidate(prev: SearchSuccess, ref: TermRef, level: Int): Int =
11031101
if (prev.ref eq ref) 0
11041102
else if (prev.level != level) prev.level - level
1105-
else nestedContext().test(implicit ctx => compare(prev.ref, ref, prev.level, level))
1103+
else nestedContext().test(implicit ctx => compare(prev.ref, ref))
11061104

11071105
/** If `alt1` is also a search success, try to disambiguate as follows:
11081106
* - If alt2 is preferred over alt1, pick alt2, otherwise return an

0 commit comments

Comments
 (0)