@@ -928,8 +928,8 @@ trait Implicits:
928928 /** Find an implicit argument for parameter `formal`.
929929 * Return a failure as a SearchFailureType in the type of the returned tree.
930930 */
931- def inferImplicitArg (formal : Type , span : Span )(using Context ): Tree =
932- inferImplicit(formal, EmptyTree , span) match
931+ def inferImplicitArg (formal : Type , span : Span , ignored : Set [ Symbol ] = Set .empty )(using Context ): Tree =
932+ inferImplicit(formal, EmptyTree , span, ignored ) match
933933 case SearchSuccess (arg, _, _, _) => arg
934934 case fail @ SearchFailure (failed) =>
935935 if fail.isAmbiguous then failed
@@ -1082,7 +1082,7 @@ trait Implicits:
10821082 * it should be applied, EmptyTree otherwise.
10831083 * @param span The position where errors should be reported.
10841084 */
1085- def inferImplicit (pt : Type , argument : Tree , span : Span )(using Context ): SearchResult = ctx.profiler.onImplicitSearch(pt):
1085+ def inferImplicit (pt : Type , argument : Tree , span : Span , ignored : Set [ Symbol ] = Set .empty )(using Context ): SearchResult = ctx.profiler.onImplicitSearch(pt):
10861086 trace(s " search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}" , implicits, show = true ) {
10871087 record(" inferImplicit" )
10881088 assert(ctx.phase.allowsImplicitSearch,
@@ -1110,7 +1110,7 @@ trait Implicits:
11101110 else i " conversion from ${argument.tpe} to $pt"
11111111
11121112 CyclicReference .trace(i " searching for an implicit $searchStr" ):
1113- try ImplicitSearch (pt, argument, span)(using searchCtx).bestImplicit
1113+ try ImplicitSearch (pt, argument, span, ignored )(using searchCtx).bestImplicit
11141114 catch case ce : CyclicReference =>
11151115 ce.inImplicitSearch = true
11161116 throw ce
@@ -1130,9 +1130,9 @@ trait Implicits:
11301130 result
11311131 case result : SearchFailure if result.isAmbiguous =>
11321132 val deepPt = pt.deepenProto
1133- if (deepPt ne pt) inferImplicit(deepPt, argument, span)
1133+ if (deepPt ne pt) inferImplicit(deepPt, argument, span, ignored )
11341134 else if (migrateTo3 && ! ctx.mode.is(Mode .OldImplicitResolution ))
1135- withMode(Mode .OldImplicitResolution )(inferImplicit(pt, argument, span)) match {
1135+ withMode(Mode .OldImplicitResolution )(inferImplicit(pt, argument, span, ignored )) match {
11361136 case altResult : SearchSuccess =>
11371137 report.migrationWarning(
11381138 result.reason.msg
@@ -1243,7 +1243,7 @@ trait Implicits:
12431243 }
12441244
12451245 /** An implicit search; parameters as in `inferImplicit` */
1246- class ImplicitSearch (protected val pt : Type , protected val argument : Tree , span : Span )(using Context ):
1246+ class ImplicitSearch (protected val pt : Type , protected val argument : Tree , span : Span , ignored : Set [ Symbol ] )(using Context ):
12471247 assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf [ExprType ],
12481248 em " found: $argument: ${argument.tpe}, expected: $pt" )
12491249
@@ -1670,14 +1670,17 @@ trait Implicits:
16701670 SearchFailure (TooUnspecific (pt), span)
16711671 else
16721672 val contextual = ctxImplicits != null
1673- val preEligible = // the eligible candidates, ignoring positions
1673+ var preEligible = // the eligible candidates, ignoring positions
16741674 if ctxImplicits != null then
16751675 if ctx.gadt.isNarrowing then
16761676 withoutMode(Mode .ImplicitsEnabled ) {
16771677 ctxImplicits.uncachedEligible(wildProto)
16781678 }
16791679 else ctxImplicits.eligible(wildProto)
16801680 else implicitScope(wildProto).eligible
1681+ if ! ignored.isEmpty then
1682+ preEligible =
1683+ preEligible.filter(candidate => ! ignored.contains(candidate.implicitRef.underlyingRef.symbol))
16811684
16821685 /** Does candidate `cand` come too late for it to be considered as an
16831686 * eligible candidate? This is the case if `cand` appears in the same
0 commit comments