@@ -25,7 +25,7 @@ import Constants._
2525import ProtoTypes ._
2626import ErrorReporting ._
2727import reporting .diagnostic .Message
28- import Inferencing .fullyDefinedType
28+ import Inferencing .{ fullyDefinedType , isFullyDefined }
2929import Trees ._
3030import transform .SymUtils ._
3131import transform .TypeUtils ._
@@ -392,7 +392,8 @@ object Implicits {
392392 def whyNoConversion (implicit ctx : Context ): String = " "
393393 }
394394
395- class NoMatchingImplicits (val expectedType : Type , val argument : Tree , constraint : Constraint = OrderingConstraint .empty) extends SearchFailureType {
395+ class NoMatchingImplicits (val expectedType : Type , val argument : Tree , constraint : Constraint = OrderingConstraint .empty)
396+ extends SearchFailureType {
396397
397398 /** Replace all type parameters in constraint by their bounds, to make it clearer
398399 * what was expected
@@ -1215,15 +1216,21 @@ trait Implicits { self: Typer =>
12151216 if (ctx == NoContext ) ctx
12161217 else ctx.freshOver(FindHiddenImplicitsCtx (ctx.outer)).addMode(Mode .FindHiddenImplicits )
12171218
1218- inferImplicit(fail.expectedType, fail.argument, arg.span)(
1219- FindHiddenImplicitsCtx (ctx)) match {
1220- case s : SearchSuccess => hiddenImplicitNote(s)
1221- case f : SearchFailure =>
1222- f.reason match {
1223- case ambi : AmbiguousImplicits => hiddenImplicitNote(ambi.alt1)
1224- case r => " "
1225- }
1226- }
1219+ if (fail.expectedType eq pt) || isFullyDefined(fail.expectedType, ForceDegree .none) then
1220+ inferImplicit(fail.expectedType, fail.argument, arg.span)(
1221+ FindHiddenImplicitsCtx (ctx)) match {
1222+ case s : SearchSuccess => hiddenImplicitNote(s)
1223+ case f : SearchFailure =>
1224+ f.reason match {
1225+ case ambi : AmbiguousImplicits => hiddenImplicitNote(ambi.alt1)
1226+ case r => " "
1227+ }
1228+ }
1229+ else
1230+ // It's unsafe to search for parts of the expected type if they are not fully defined,
1231+ // since these come with nested contexts that are lost at this point. See #7249 for an
1232+ // example where searching for a nested type causes an infinite loop.
1233+ " "
12271234 }
12281235 msg(userDefined.getOrElse(
12291236 em " no implicit argument of type $pt was found ${location(" for" )}" ))() ++
0 commit comments