@@ -901,7 +901,7 @@ trait Implicits:
901
901
}
902
902
903
903
try
904
- val inferred = inferImplicit(adjust(to), from, from.span)
904
+ val inferred = inferImplicit(adjust(to), from, from.span, ignored = Set .empty )
905
905
906
906
inferred match {
907
907
case SearchSuccess (_, ref, _, false ) if isOldStyleFunctionConversion(ref.underlying) =>
@@ -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 ] )(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
@@ -944,7 +944,7 @@ trait Implicits:
944
944
945
945
/** Search an implicit argument and report error if not found */
946
946
def implicitArgTree (formal : Type , span : Span , where : => String = " " )(using Context ): Tree = {
947
- val arg = inferImplicitArg(formal, span)
947
+ val arg = inferImplicitArg(formal, span, ignored = Set .empty )
948
948
if (arg.tpe.isInstanceOf [SearchFailureType ])
949
949
report.error(missingArgMsg(arg, formal, where), ctx.source.atSpan(span))
950
950
arg
@@ -968,7 +968,7 @@ trait Implicits:
968
968
def ignoredInstanceNormalImport = arg.tpe match
969
969
case fail : SearchFailureType =>
970
970
if (fail.expectedType eq pt) || isFullyDefined(fail.expectedType, ForceDegree .none) then
971
- inferImplicit(fail.expectedType, fail.argument, arg.span)(
971
+ inferImplicit(fail.expectedType, fail.argument, arg.span, Set .empty )(
972
972
using findHiddenImplicitsCtx(ctx)) match {
973
973
case s : SearchSuccess => Some (s)
974
974
case f : SearchFailure =>
@@ -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 ] )(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
@@ -1684,7 +1684,7 @@ trait Implicits:
1684
1684
SearchFailure (TooUnspecific (pt), span)
1685
1685
else
1686
1686
val contextual = ctxImplicits != null
1687
- val preEligible = // the eligible candidates, ignoring positions
1687
+ val prePreEligible = // the eligible candidates, ignoring positions
1688
1688
if ctxImplicits != null then
1689
1689
if ctx.gadt.isNarrowing then
1690
1690
withoutMode(Mode .ImplicitsEnabled ) {
@@ -1693,6 +1693,8 @@ trait Implicits:
1693
1693
else ctxImplicits.eligible(wildProto)
1694
1694
else implicitScope(wildProto).eligible
1695
1695
1696
+ val preEligible =
1697
+ prePreEligible.filter(candidate => ! ignored.contains(candidate.implicitRef.underlyingRef.symbol))
1696
1698
/** Does candidate `cand` come too late for it to be considered as an
1697
1699
* eligible candidate? This is the case if `cand` appears in the same
1698
1700
* scope as a given definition of the form `given ... = ...` that
0 commit comments