@@ -299,7 +299,7 @@ object Implicits:
299299 class ContextualImplicits (
300300 val refs : List [ImplicitRef ],
301301 val outerImplicits : ContextualImplicits | Null ,
302- isImport : Boolean )(initctx : Context ) extends ImplicitRefs (initctx) {
302+ val isImport : Boolean )(initctx : Context ) extends ImplicitRefs (initctx) {
303303 private val eligibleCache = EqHashMap [Type , List [Candidate ]]()
304304
305305 /** The level increases if current context has a different owner or scope than
@@ -330,8 +330,19 @@ object Implicits:
330330 if ownEligible.isEmpty then outerEligible
331331 else if outerEligible.isEmpty then ownEligible
332332 else
333- val shadowed = ownEligible.map(_.ref.implicitName).toSet
334- ownEligible ::: outerEligible.filterConserve(cand => ! shadowed.contains(cand.ref.implicitName))
333+ def filter (xs : List [Candidate ], remove : List [Candidate ]) =
334+ val shadowed = remove.map(_.ref.implicitName).toSet
335+ xs.filterConserve(cand => ! shadowed.contains(cand.ref.implicitName))
336+ def isWildcardImport (using Context ) = ctx.importInfo.nn.isWildcardImport
337+ if (irefCtx.scope eq irefCtx.outer.scope) && (
338+ isImport && ! outerImplicits.nn.isImport
339+ || isWildcardImport && ! isWildcardImport(using outerImplicits.nn.irefCtx)
340+ ) then
341+ // special cases: definitions beat imports, and named imports beat
342+ // wildcard imports, provided both are in contexts with same scope
343+ filter(ownEligible, outerEligible) ::: outerEligible
344+ else
345+ ownEligible ::: filter(outerEligible, ownEligible)
335346
336347 def uncachedEligible (tp : Type )(using Context ): List [Candidate ] =
337348 Stats .record(" uncached eligible" )
0 commit comments