summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2010-08-20 14:48:12 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2010-08-20 14:48:12 +0000
commite11cac6ecc3c8791be3a37fc3b9f6837c9d46d23 (patch)
treedfa0ddc52703125288c6d7a85c4dc7befdb1508c /src/library
parentd4645f93728ee8cb40a17c23f92a272e27052889 (diff)
downloadscala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.tar.gz
scala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.tar.bz2
scala-e11cac6ecc3c8791be3a37fc3b9f6837c9d46d23.zip
closes 2462. better implicit error messages.
@implicitNotFound(msg="Custom error message that may refer to type parameters ${T} and ${U}") trait Constraint[T, U] whenever an implicit argument of type Constraint[A, B] cannot be found, the custom error message will be used, where the type arguments are interpolated in the obvious way note: if the msg in the annotation references non-existing type params, a warning is emitted the patch also cleans up annotation argument retrieval (moved it to AnnotationInfo from Symbol) review by odersky
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/annotation/implicitNotFound.scala18
-rw-r--r--src/library/scala/collection/generic/CanBuildFrom.scala3
2 files changed, 20 insertions, 1 deletions
diff --git a/src/library/scala/annotation/implicitNotFound.scala b/src/library/scala/annotation/implicitNotFound.scala
new file mode 100644
index 0000000000..5d9b29c5f8
--- /dev/null
+++ b/src/library/scala/annotation/implicitNotFound.scala
@@ -0,0 +1,18 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.annotation
+
+/**
+ * An annotation that specifies the error message that is emitted when the compiler
+ * cannot find an implicit value of the annotated type.
+ *
+ * @author Adriaan Moors
+ * @since 2.8.1
+ */
+final class implicitNotFound(msg: String) extends StaticAnnotation {} \ No newline at end of file
diff --git a/src/library/scala/collection/generic/CanBuildFrom.scala b/src/library/scala/collection/generic/CanBuildFrom.scala
index 79e352690e..4c923dca44 100644
--- a/src/library/scala/collection/generic/CanBuildFrom.scala
+++ b/src/library/scala/collection/generic/CanBuildFrom.scala
@@ -11,7 +11,7 @@ package scala.collection
package generic
import mutable.Builder
-
+import scala.annotation.implicitNotFound
/** A base trait for builder factories.
*
@@ -25,6 +25,7 @@ import mutable.Builder
* @author Adriaan Moors
* @since 2.8
*/
+@implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${To}.")
trait CanBuildFrom[-From, -Elem, +To] {
/** Creates a new builder on request of a collection.