@@ -23,6 +23,7 @@ import ProtoTypes._
23
23
import ErrorReporting ._
24
24
import Inferencing .{fullyDefinedType , isFullyDefined }
25
25
import Scopes .newScope
26
+ import Typer .BindingPrec , BindingPrec .*
26
27
import transform .TypeUtils ._
27
28
import Hashable ._
28
29
import util .{EqHashMap , Stats }
@@ -328,25 +329,28 @@ object Implicits:
328
329
(this eq finalImplicits) || (outerImplicits eqn finalImplicits)
329
330
}
330
331
332
+ def bindingPrec : BindingPrec =
333
+ if isImport then if ctx.importInfo.uncheckedNN.isWildcardImport then WildImport else NamedImport else Definition
334
+
331
335
private def combineEligibles (ownEligible : List [Candidate ], outerEligible : List [Candidate ]): List [Candidate ] =
332
336
if ownEligible.isEmpty then outerEligible
333
337
else if outerEligible.isEmpty then ownEligible
334
338
else
335
- def filter (xs : List [Candidate ], remove : List [Candidate ]) =
336
- val shadowed = remove.map(_.ref.implicitName).toSet
337
- xs.filterConserve(cand => ! shadowed.contains(cand.ref.implicitName))
338
-
339
+ val ownNames = mutable.Set (ownEligible.map(_.ref.implicitName)* )
339
340
val outer = outerImplicits.uncheckedNN
340
- def isWildcardImport (using Context ) = ctx.importInfo.nn.isWildcardImport
341
- def preferDefinitions = isImport && ! outer.isImport
342
- def preferNamedImport = isWildcardImport && ! isWildcardImport(using outer.irefCtx)
343
-
344
- if ! migrateTo3(using irefCtx) && level == outer.level && (preferDefinitions || preferNamedImport) then
345
- // special cases: definitions beat imports, and named imports beat
346
- // wildcard imports, provided both are in contexts with same scope
347
- filter(ownEligible, outerEligible) ::: outerEligible
341
+ if ! migrateTo3(using irefCtx) && level == outer.level && outer.bindingPrec.beats(bindingPrec) then
342
+ val keptOuters = outerEligible.filterConserve: cand =>
343
+ if ownNames.contains(cand.ref.implicitName) then
344
+ val keepOuter = cand.level == level
345
+ if keepOuter then ownNames -= cand.ref.implicitName
346
+ keepOuter
347
+ else true
348
+ val keptOwn = ownEligible.filterConserve: cand =>
349
+ ownNames.contains(cand.ref.implicitName)
350
+ keptOwn ::: keptOuters
348
351
else
349
- ownEligible ::: filter(outerEligible, ownEligible)
352
+ ownEligible ::: outerEligible.filterConserve: cand =>
353
+ ! ownNames.contains(cand.ref.implicitName)
350
354
351
355
def uncachedEligible (tp : Type )(using Context ): List [Candidate ] =
352
356
Stats .record(" uncached eligible" )
0 commit comments