@@ -928,8 +928,8 @@ trait Implicits:
928
928
/** Find an implicit argument for parameter `formal`.
929
929
* Return a failure as a SearchFailureType in the type of the returned tree.
930
930
*/
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
933
933
case SearchSuccess (arg, _, _, _) => arg
934
934
case fail @ SearchFailure (failed) =>
935
935
if fail.isAmbiguous then failed
@@ -1082,7 +1082,7 @@ trait Implicits:
1082
1082
* it should be applied, EmptyTree otherwise.
1083
1083
* @param span The position where errors should be reported.
1084
1084
*/
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):
1086
1086
trace(s " search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}" , implicits, show = true ) {
1087
1087
record(" inferImplicit" )
1088
1088
assert(ctx.phase.allowsImplicitSearch,
@@ -1110,7 +1110,7 @@ trait Implicits:
1110
1110
else i " conversion from ${argument.tpe} to $pt"
1111
1111
1112
1112
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
1114
1114
catch case ce : CyclicReference =>
1115
1115
ce.inImplicitSearch = true
1116
1116
throw ce
@@ -1130,9 +1130,9 @@ trait Implicits:
1130
1130
result
1131
1131
case result : SearchFailure if result.isAmbiguous =>
1132
1132
val deepPt = pt.deepenProto
1133
- if (deepPt ne pt) inferImplicit(deepPt, argument, span)
1133
+ if (deepPt ne pt) inferImplicit(deepPt, argument, span, ignored )
1134
1134
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 {
1136
1136
case altResult : SearchSuccess =>
1137
1137
report.migrationWarning(
1138
1138
result.reason.msg
@@ -1243,7 +1243,7 @@ trait Implicits:
1243
1243
}
1244
1244
1245
1245
/** 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 ):
1247
1247
assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf [ExprType ],
1248
1248
em " found: $argument: ${argument.tpe}, expected: $pt" )
1249
1249
@@ -1670,14 +1670,17 @@ trait Implicits:
1670
1670
SearchFailure (TooUnspecific (pt), span)
1671
1671
else
1672
1672
val contextual = ctxImplicits != null
1673
- val preEligible = // the eligible candidates, ignoring positions
1673
+ var preEligible = // the eligible candidates, ignoring positions
1674
1674
if ctxImplicits != null then
1675
1675
if ctx.gadt.isNarrowing then
1676
1676
withoutMode(Mode .ImplicitsEnabled ) {
1677
1677
ctxImplicits.uncachedEligible(wildProto)
1678
1678
}
1679
1679
else ctxImplicits.eligible(wildProto)
1680
1680
else implicitScope(wildProto).eligible
1681
+ if ! ignored.isEmpty then
1682
+ preEligible =
1683
+ preEligible.filter(candidate => ! ignored.contains(candidate.implicitRef.underlyingRef.symbol))
1681
1684
1682
1685
/** Does candidate `cand` come too late for it to be considered as an
1683
1686
* eligible candidate? This is the case if `cand` appears in the same
0 commit comments