@@ -687,6 +687,9 @@ trait Implicits { self: Typer =>
687
687
}
688
688
def location (preposition : String ) = if (where.isEmpty) " " else s " $preposition $where"
689
689
690
+ /** Extract a user defined error message from a symbol `sym`
691
+ * with an annotation matching the given class symbol `cls`.
692
+ */
690
693
def userDefinedMsg (sym : Symbol , cls : Symbol ) = for {
691
694
ann <- sym.getAnnotation(cls)
692
695
Trees .Literal (Constant (msg : String )) <- ann.argument(0 )
@@ -696,10 +699,13 @@ trait Implicits { self: Typer =>
696
699
arg.tpe match {
697
700
case ambi : AmbiguousImplicits =>
698
701
object AmbiguousImplicitMsg {
699
- def unapply (search : SearchSuccess ) =
702
+ def unapply (search : SearchSuccess ): Option [ String ] =
700
703
userDefinedMsg(search.ref.symbol, defn.ImplicitAmbiguousAnnot )
701
704
}
702
705
706
+ /** Construct a custom error message given an ambiguous implicit
707
+ * candidate `alt` and a user defined message `raw`.
708
+ */
703
709
def userDefinedAmbiguousImplicitMsg (alt : SearchSuccess , raw : String ) = {
704
710
val params = alt.ref.underlying match {
705
711
case p : PolyType => p.paramNames.map(_.toString)
@@ -726,10 +732,10 @@ trait Implicits { self: Typer =>
726
732
}
727
733
728
734
(ambi.alt1, ambi.alt2) match {
729
- case (AmbiguousImplicitMsg (msg), _) =>
730
- userDefinedAmbiguousImplicitMsg(ambi.alt1 , msg)
731
- case (_, AmbiguousImplicitMsg (msg)) =>
732
- userDefinedAmbiguousImplicitMsg(ambi.alt2 , msg)
735
+ case (alt @ AmbiguousImplicitMsg (msg), _) =>
736
+ userDefinedAmbiguousImplicitMsg(alt , msg)
737
+ case (_, alt @ AmbiguousImplicitMsg (msg)) =>
738
+ userDefinedAmbiguousImplicitMsg(alt , msg)
733
739
case _ =>
734
740
msg(s " ambiguous implicit arguments: ${ambi.explanation}${location(" of" )}" )(
735
741
s " ambiguous implicit arguments of type ${pt.show} found ${location(" for" )}" )
0 commit comments