@@ -687,6 +687,9 @@ trait Implicits { self: Typer =>
687687 }
688688 def location (preposition : String ) = if (where.isEmpty) " " else s " $preposition $where"
689689
690+ /** Extract a user defined error message from a symbol `sym`
691+ * with an annotation matching the given class symbol `cls`.
692+ */
690693 def userDefinedMsg (sym : Symbol , cls : Symbol ) = for {
691694 ann <- sym.getAnnotation(cls)
692695 Trees .Literal (Constant (msg : String )) <- ann.argument(0 )
@@ -696,10 +699,13 @@ trait Implicits { self: Typer =>
696699 arg.tpe match {
697700 case ambi : AmbiguousImplicits =>
698701 object AmbiguousImplicitMsg {
699- def unapply (search : SearchSuccess ) =
702+ def unapply (search : SearchSuccess ): Option [ String ] =
700703 userDefinedMsg(search.ref.symbol, defn.ImplicitAmbiguousAnnot )
701704 }
702705
706+ /** Construct a custom error message given an ambiguous implicit
707+ * candidate `alt` and a user defined message `raw`.
708+ */
703709 def userDefinedAmbiguousImplicitMsg (alt : SearchSuccess , raw : String ) = {
704710 val params = alt.ref.underlying match {
705711 case p : PolyType => p.paramNames.map(_.toString)
@@ -726,10 +732,10 @@ trait Implicits { self: Typer =>
726732 }
727733
728734 (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)
733739 case _ =>
734740 msg(s " ambiguous implicit arguments: ${ambi.explanation}${location(" of" )}" )(
735741 s " ambiguous implicit arguments of type ${pt.show} found ${location(" for" )}" )
0 commit comments