@@ -330,11 +330,25 @@ object Implicits:
330
330
(this eq finalImplicits) || (outerImplicits eq finalImplicits)
331
331
}
332
332
333
+ private def combineEligibles (ownEligible : List [Candidate ], outerEligible : List [Candidate ]): List [Candidate ] =
334
+ if ownEligible.isEmpty then outerEligible
335
+ else if outerEligible.isEmpty then ownEligible
336
+ else
337
+ val shadowed = ownEligible.map(_.ref.implicitName).toSet
338
+ ownEligible ::: outerEligible.filterConserve(cand => ! shadowed.contains(cand.ref.implicitName))
339
+
340
+ def uncachedEligible (tp : Type )(using Context ): List [Candidate ] =
341
+ Stats .record(" uncached eligible" )
342
+ if monitored then record(s " check uncached eligible refs in irefCtx " , refs.length)
343
+ val ownEligible = filterMatching(tp)
344
+ if isOuterMost then ownEligible
345
+ else combineEligibles(ownEligible, outerImplicits.uncachedEligible(tp))
346
+
333
347
/** The implicit references that are eligible for type `tp`. */
334
348
def eligible (tp : Type ): List [Candidate ] =
335
349
if (tp.hash == NotCached )
336
350
Stats .record(i " compute eligible not cached ${tp.getClass}" )
337
- Stats .record(i " compute eligible not cached " )
351
+ Stats .record(" compute eligible not cached" )
338
352
computeEligible(tp)
339
353
else {
340
354
val eligibles = eligibleCache.lookup(tp)
@@ -354,14 +368,8 @@ object Implicits:
354
368
private def computeEligible (tp : Type ): List [Candidate ] = /* >|>*/ trace(i " computeEligible $tp in $refs%, % " , implicitsDetailed) /* <|<*/ {
355
369
if (monitored) record(s " check eligible refs in irefCtx " , refs.length)
356
370
val ownEligible = filterMatching(tp)
357
- if (isOuterMost) ownEligible
358
- else if ownEligible.isEmpty then outerImplicits.eligible(tp)
359
- else
360
- val outerEligible = outerImplicits.eligible(tp)
361
- if outerEligible.isEmpty then ownEligible
362
- else
363
- val shadowed = ownEligible.map(_.ref.implicitName).toSet
364
- ownEligible ::: outerEligible.filterConserve(cand => ! shadowed.contains(cand.ref.implicitName))
371
+ if isOuterMost then ownEligible
372
+ else combineEligibles(ownEligible, outerImplicits.eligible(tp))
365
373
}
366
374
367
375
override def isAccessible (ref : TermRef )(using Context ): Boolean =
@@ -1444,7 +1452,12 @@ trait Implicits:
1444
1452
NoMatchingImplicitsFailure
1445
1453
else
1446
1454
val eligible =
1447
- if contextual then ctx.implicits.eligible(wildProto)
1455
+ if contextual then
1456
+ if ctx.gadt.isNarrowing then
1457
+ withoutMode(Mode .ImplicitsEnabled ) {
1458
+ ctx.implicits.uncachedEligible(wildProto)
1459
+ }
1460
+ else ctx.implicits.eligible(wildProto)
1448
1461
else implicitScope(wildProto).eligible
1449
1462
searchImplicit(eligible, contextual) match
1450
1463
case result : SearchSuccess =>
0 commit comments