@@ -31,6 +31,7 @@ import Feature.migrateTo3
3131import config .Printers .{implicits , implicitsDetailed }
3232import collection .mutable
3333import reporting ._
34+ import transform .Splicer
3435import annotation .tailrec
3536
3637import scala .annotation .internal .sharable
@@ -567,6 +568,12 @@ object Implicits:
567568
568569 def msg (using Context ) = em " Failed to synthesize an instance of type ${clarify(expectedType)}: ${formatReasons}"
569570
571+ class MacroErrorsFailure (errors : List [Diagnostic .Error ],
572+ val expectedType : Type ,
573+ val argument : Tree ) extends SearchFailureType {
574+ def msg (using Context ): Message =
575+ em " ${errors.map(_.msg).mkString(" \n " )}"
576+ }
570577end Implicits
571578
572579import Implicits ._
@@ -1157,19 +1164,22 @@ trait Implicits:
11571164 if ctx.reporter.hasErrors
11581165 || ! cand.ref.symbol.isAccessibleFrom(cand.ref.prefix)
11591166 then
1160- ctx.reporter.removeBufferedMessages
1161- adapted.tpe match {
1167+ val res = adapted.tpe match {
11621168 case _ : SearchFailureType => SearchFailure (adapted)
11631169 case error : PreviousErrorType if ! adapted.symbol.isAccessibleFrom(cand.ref.prefix) =>
11641170 SearchFailure (adapted.withType(new NestedFailure (error.msg, pt)))
1165- case _ =>
1171+ case tpe =>
11661172 // Special case for `$conforms` and `<:<.refl`. Showing them to the users brings
11671173 // no value, so we instead report a `NoMatchingImplicitsFailure`
11681174 if (adapted.symbol == defn.Predef_conforms || adapted.symbol == defn.SubType_refl )
11691175 NoMatchingImplicitsFailure
1176+ else if Splicer .inMacroExpansion && tpe <:< pt then
1177+ SearchFailure (adapted.withType(new MacroErrorsFailure (ctx.reporter.allErrors.reverse, pt, argument)))
11701178 else
11711179 SearchFailure (adapted.withType(new MismatchedImplicit (ref, pt, argument)))
11721180 }
1181+ ctx.reporter.removeBufferedMessages
1182+ res
11731183 else
11741184 SearchSuccess (adapted, ref, cand.level, cand.isExtension)(ctx.typerState, ctx.gadt)
11751185 }
0 commit comments