implicitAmbiguous (original) (raw)
scala.annotation.implicitAmbiguous
To customize the error message that's emitted when an implicit search finds multiple ambiguous values, annotate at least one of the implicit values @implicitAmbiguous
. Assuming the implicit value is a method with type parameters X1,..., XN
, the error message will be the result of replacing all occurrences of ${Xi}
in the string msg
with the string representation of the corresponding type argument Ti
.
If more than one @implicitAmbiguous
annotation is collected, the compiler is free to pick any of them to display.
Nice errors can direct users to fix imports or even tell them why code intentionally doesn't compile.
trait =!=[C, D]
implicit def neq[E, F] : E =!= F = null
@annotation.implicitAmbiguous("Could not prove <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>J</mi><mo>=</mo><mo stretchy="false">!</mo><mo>=</mo></mrow><annotation encoding="application/x-tex">{J} =!= </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.09618em;">J</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mclose">!</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>{J}")
implicit def neqAmbig1[G, H, J] : J =!= J = null
implicit def neqAmbig2[I] : I =!= I = null
implicitly[Int =!= Int]
Attributes
Source
Graph
Supertypes
In this article