diff options
Diffstat (limited to 'src/library/scala/annotation/implicitAmbiguous.scala')
-rw-r--r-- | src/library/scala/annotation/implicitAmbiguous.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/library/scala/annotation/implicitAmbiguous.scala b/src/library/scala/annotation/implicitAmbiguous.scala new file mode 100644 index 0000000000..44e8d23085 --- /dev/null +++ b/src/library/scala/annotation/implicitAmbiguous.scala @@ -0,0 +1,32 @@ +package scala.annotation + +/** + * 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 ${J} =!= ${J}") + * implicit def neqAmbig1[G, H, J] : J =!= J = null + * implicit def neqAmbig2[I] : I =!= I = null + * + * implicitly[Int =!= Int] + * }}} + * + * @author Brian McKenna + * @since 2.12.0 + */ +final class implicitAmbiguous(msg: String) extends scala.annotation.StaticAnnotation |