@@ -23,6 +23,7 @@ import ProtoTypes._
2323import ErrorReporting ._
2424import Inferencing .{fullyDefinedType , isFullyDefined }
2525import Scopes .newScope
26+ import Typer .BindingPrec , BindingPrec .*
2627import transform .TypeUtils ._
2728import Hashable ._
2829import util .{EqHashMap , Stats }
@@ -328,25 +329,28 @@ object Implicits:
328329 (this eq finalImplicits) || (outerImplicits eqn finalImplicits)
329330 }
330331
332+ def bindingPrec : BindingPrec =
333+ if isImport then if ctx.importInfo.uncheckedNN.isWildcardImport then WildImport else NamedImport else Definition
334+
331335 private def combineEligibles (ownEligible : List [Candidate ], outerEligible : List [Candidate ]): List [Candidate ] =
332336 if ownEligible.isEmpty then outerEligible
333337 else if outerEligible.isEmpty then ownEligible
334338 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)* )
339340 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
348351 else
349- ownEligible ::: filter(outerEligible, ownEligible)
352+ ownEligible ::: outerEligible.filterConserve: cand =>
353+ ! ownNames.contains(cand.ref.implicitName)
350354
351355 def uncachedEligible (tp : Type )(using Context ): List [Candidate ] =
352356 Stats .record(" uncached eligible" )
0 commit comments