Skip to content

Commit 1019f77

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 8e87613 commit 1019f77

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
@@ -1182,21 +1182,17 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
11821182
/** Compare to alternatives of an overloaded call or an implicit search.
11831183
*
11841184
* @param alt1, alt2 Non-overloaded references indicating the two choices
1185-
* @param level1, level2 If alternatives come from a comparison of two contextual
1186-
* implicit candidates, the nesting levels of the candidates.
1187-
* In all other cases the nesting levels are both 0.
11881185
* @return 1 if 1st alternative is preferred over 2nd
11891186
* -1 if 2nd alternative is preferred over 1st
11901187
* 0 if neither alternative is preferred over the other
11911188
*
11921189
* An alternative A1 is preferred over an alternative A2 if it wins in a tournament
11931190
* that awards one point for each of the following:
11941191
*
1195-
* - A1 is nested more deeply than A2
1196-
* - The nesting levels of A1 and A2 are the same, and A1's owner derives from A2's owner
1192+
* - A1's owner derives from A2's owner.
11971193
* - A1's type is more specific than A2's type.
11981194
*/
1199-
def compare(alt1: TermRef, alt2: TermRef, nesting1: Int = 0, nesting2: Int = 0)(implicit ctx: Context): Int = track("compare") { trace(i"compare($alt1, $alt2)", overload) {
1195+
def compare(alt1: TermRef, alt2: TermRef)(implicit ctx: Context): Int = track("compare") { trace(i"compare($alt1, $alt2)", overload) {
12001196

12011197
assert(alt1 ne alt2)
12021198

@@ -1306,10 +1302,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
13061302

13071303
val owner1 = if (alt1.symbol.exists) alt1.symbol.owner else NoSymbol
13081304
val owner2 = if (alt2.symbol.exists) alt2.symbol.owner else NoSymbol
1309-
val ownerScore =
1310-
if (nesting1 > nesting2) 1
1311-
else if (nesting1 < nesting2) -1
1312-
else compareOwner(owner1, owner2)
1305+
val ownerScore = compareOwner(owner1, owner2)
13131306

13141307
val tp1 = stripImplicit(alt1.widen)
13151308
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
@@ -1034,9 +1034,6 @@ trait Implicits { self: Typer =>
10341034

10351035
private def isCoherent = pt.isRef(defn.EqlClass)
10361036

1037-
private val cmpContext = nestedContext()
1038-
private val cmpCandidates = (c1: Candidate, c2: Candidate) => compare(c1.ref, c2.ref, c1.level, c2.level)(cmpContext)
1039-
10401037
/** The expected type for the searched implicit */
10411038
lazy val fullProto: Type = implicitProto(pt, identity)
10421039

@@ -1143,13 +1140,14 @@ trait Implicits { self: Typer =>
11431140

11441141
/** Search a list of eligible implicit references */
11451142
def searchImplicits(eligible: List[Candidate], contextual: Boolean): SearchResult = {
1143+
11461144
/** Compare previous success with reference and level to determine which one would be chosen, if
11471145
* an implicit starting with the reference was found.
11481146
*/
11491147
def compareCandidate(prev: SearchSuccess, ref: TermRef, level: Int): Int =
11501148
if (prev.ref eq ref) 0
11511149
else if (prev.level != level) prev.level - level
1152-
else nestedContext().test(implicit ctx => compare(prev.ref, ref, prev.level, level))
1150+
else nestedContext().test(implicit ctx => compare(prev.ref, ref))
11531151

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

0 commit comments

Comments
 (0)