@@ -299,7 +299,7 @@ object Implicits:
299
299
class ContextualImplicits (
300
300
val refs : List [ImplicitRef ],
301
301
val outerImplicits : ContextualImplicits | Null ,
302
- isImport : Boolean )(initctx : Context ) extends ImplicitRefs (initctx) {
302
+ val isImport : Boolean )(initctx : Context ) extends ImplicitRefs (initctx) {
303
303
private val eligibleCache = EqHashMap [Type , List [Candidate ]]()
304
304
305
305
/** The level increases if current context has a different owner or scope than
@@ -330,8 +330,19 @@ object Implicits:
330
330
if ownEligible.isEmpty then outerEligible
331
331
else if outerEligible.isEmpty then ownEligible
332
332
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)
335
346
336
347
def uncachedEligible (tp : Type )(using Context ): List [Candidate ] =
337
348
Stats .record(" uncached eligible" )
0 commit comments