@@ -25,7 +25,7 @@ import Constants._
25
25
import ProtoTypes ._
26
26
import ErrorReporting ._
27
27
import reporting .diagnostic .Message
28
- import Inferencing .fullyDefinedType
28
+ import Inferencing .{ fullyDefinedType , isFullyDefined }
29
29
import Trees ._
30
30
import transform .SymUtils ._
31
31
import transform .TypeUtils ._
@@ -392,7 +392,8 @@ object Implicits {
392
392
def whyNoConversion (implicit ctx : Context ): String = " "
393
393
}
394
394
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 {
396
397
397
398
/** Replace all type parameters in constraint by their bounds, to make it clearer
398
399
* what was expected
@@ -1215,15 +1216,21 @@ trait Implicits { self: Typer =>
1215
1216
if (ctx == NoContext ) ctx
1216
1217
else ctx.freshOver(FindHiddenImplicitsCtx (ctx.outer)).addMode(Mode .FindHiddenImplicits )
1217
1218
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
+ " "
1227
1234
}
1228
1235
msg(userDefined.getOrElse(
1229
1236
em " no implicit argument of type $pt was found ${location(" for" )}" ))() ++
0 commit comments