@@ -31,6 +31,7 @@ import Feature.migrateTo3
31
31
import config .Printers .{implicits , implicitsDetailed }
32
32
import collection .mutable
33
33
import reporting ._
34
+ import transform .Splicer
34
35
import annotation .tailrec
35
36
36
37
import scala .annotation .internal .sharable
@@ -567,6 +568,12 @@ object Implicits:
567
568
568
569
def msg (using Context ) = em " Failed to synthesize an instance of type ${clarify(expectedType)}: ${formatReasons}"
569
570
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
+ }
570
577
end Implicits
571
578
572
579
import Implicits ._
@@ -1157,19 +1164,22 @@ trait Implicits:
1157
1164
if ctx.reporter.hasErrors
1158
1165
|| ! cand.ref.symbol.isAccessibleFrom(cand.ref.prefix)
1159
1166
then
1160
- ctx.reporter.removeBufferedMessages
1161
- adapted.tpe match {
1167
+ val res = adapted.tpe match {
1162
1168
case _ : SearchFailureType => SearchFailure (adapted)
1163
1169
case error : PreviousErrorType if ! adapted.symbol.isAccessibleFrom(cand.ref.prefix) =>
1164
1170
SearchFailure (adapted.withType(new NestedFailure (error.msg, pt)))
1165
- case _ =>
1171
+ case tpe =>
1166
1172
// Special case for `$conforms` and `<:<.refl`. Showing them to the users brings
1167
1173
// no value, so we instead report a `NoMatchingImplicitsFailure`
1168
1174
if (adapted.symbol == defn.Predef_conforms || adapted.symbol == defn.SubType_refl )
1169
1175
NoMatchingImplicitsFailure
1176
+ else if Splicer .inMacroExpansion && tpe <:< pt then
1177
+ SearchFailure (adapted.withType(new MacroErrorsFailure (ctx.reporter.allErrors.reverse, pt, argument)))
1170
1178
else
1171
1179
SearchFailure (adapted.withType(new MismatchedImplicit (ref, pt, argument)))
1172
1180
}
1181
+ ctx.reporter.removeBufferedMessages
1182
+ res
1173
1183
else
1174
1184
SearchSuccess (adapted, ref, cand.level, cand.isExtension)(ctx.typerState, ctx.gadt)
1175
1185
}
0 commit comments