@@ -676,7 +676,7 @@ trait Implicits { self: Typer =>
676
676
val isearch =
677
677
if (ctx.settings.explainImplicits.value) new ExplainedImplicitSearch (pt, argument, pos)
678
678
else new ImplicitSearch (pt, argument, pos)
679
- val result = isearch.bestImplicit
679
+ val result = isearch.bestImplicit(contextual = true )
680
680
result match {
681
681
case result : SearchSuccess =>
682
682
result.tstate.commit()
@@ -706,7 +706,7 @@ trait Implicits { self: Typer =>
706
706
}
707
707
708
708
/** An implicit search; parameters as in `inferImplicit` */
709
- class ImplicitSearch (protected val pt : Type , protected val argument : Tree , pos : Position , contextual : Boolean = true )(implicit ctx : Context ) {
709
+ class ImplicitSearch (protected val pt : Type , protected val argument : Tree , pos : Position )(implicit ctx : Context ) {
710
710
711
711
private def nestedContext = ctx.fresh.setMode(ctx.mode &~ Mode .ImplicitsEnabled )
712
712
@@ -763,7 +763,8 @@ trait Implicits { self: Typer =>
763
763
// which is different from `eqAny`?
764
764
def hasEq (tp : Type ): Boolean = {
765
765
def search (contextual : Boolean ): Boolean =
766
- new ImplicitSearch (defn.EqType .appliedTo(tp, tp), EmptyTree , pos, contextual).bestImplicit match {
766
+ new ImplicitSearch (defn.EqType .appliedTo(tp, tp), EmptyTree , pos)
767
+ .bestImplicit(contextual) match {
767
768
case result : SearchSuccess =>
768
769
result.ref.symbol != defn.Predef_eqAny ||
769
770
contextual && search(contextual = false )
@@ -878,14 +879,15 @@ trait Implicits { self: Typer =>
878
879
}
879
880
880
881
/** Find a unique best implicit reference */
881
- def bestImplicit : SearchResult = {
882
- searchImplicits(ctx.implicits.eligible(wildProto), contextual) match {
882
+ def bestImplicit (contextual : Boolean ): SearchResult = {
883
+ val eligible =
884
+ if (contextual) ctx.implicits.eligible(wildProto)
885
+ else implicitScope(wildProto).eligible
886
+ searchImplicits(eligible, contextual) match {
883
887
case result : SearchSuccess => result
884
888
case result : AmbiguousImplicits => result
885
889
case result : SearchFailure =>
886
- if (contextual)
887
- searchImplicits(implicitScope(wildProto).eligible, contextual = false )
888
- else result
890
+ if (contextual) bestImplicit(contextual = false ) else result
889
891
}
890
892
}
891
893
0 commit comments