@@ -676,7 +676,7 @@ trait Implicits { self: Typer =>
676676 val isearch =
677677 if (ctx.settings.explainImplicits.value) new ExplainedImplicitSearch (pt, argument, pos)
678678 else new ImplicitSearch (pt, argument, pos)
679- val result = isearch.bestImplicit
679+ val result = isearch.bestImplicit(contextual = true )
680680 result match {
681681 case result : SearchSuccess =>
682682 result.tstate.commit()
@@ -706,7 +706,7 @@ trait Implicits { self: Typer =>
706706 }
707707
708708 /** 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 ) {
710710
711711 private def nestedContext = ctx.fresh.setMode(ctx.mode &~ Mode .ImplicitsEnabled )
712712
@@ -763,7 +763,8 @@ trait Implicits { self: Typer =>
763763 // which is different from `eqAny`?
764764 def hasEq (tp : Type ): Boolean = {
765765 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 {
767768 case result : SearchSuccess =>
768769 result.ref.symbol != defn.Predef_eqAny ||
769770 contextual && search(contextual = false )
@@ -878,14 +879,15 @@ trait Implicits { self: Typer =>
878879 }
879880
880881 /** 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 {
883887 case result : SearchSuccess => result
884888 case result : AmbiguousImplicits => result
885889 case result : SearchFailure =>
886- if (contextual)
887- searchImplicits(implicitScope(wildProto).eligible, contextual = false )
888- else result
890+ if (contextual) bestImplicit(contextual = false ) else result
889891 }
890892 }
891893
0 commit comments