summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-28 19:20:58 +0000
committerPaul Phillips <paulp@improving.org>2011-03-28 19:20:58 +0000
commitd4392e047b61cc135f5110bf7863ec0d3480eaa6 (patch)
tree70b114cdf1ebab17c85b2d42a306e99fe340f4b3 /src/library
parenteb32c46d6929999ae19f7c7d205248eba8966249 (diff)
downloadscala-d4392e047b61cc135f5110bf7863ec0d3480eaa6.tar.gz
scala-d4392e047b61cc135f5110bf7863ec0d3480eaa6.tar.bz2
scala-d4392e047b61cc135f5110bf7863ec0d3480eaa6.zip
Added some implicitNotFound annotations to comm...
Added some implicitNotFound annotations to commonly used classes, and some documentation to Manifest. (Said documentation is invisible for the moment due to #4404.) No review.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Function1.scala1
-rw-r--r--src/library/scala/Predef.scala4
-rw-r--r--src/library/scala/collection/TraversableOnce.scala2
-rw-r--r--src/library/scala/math/Ordering.scala1
-rw-r--r--src/library/scala/reflect/ClassManifest.scala14
-rw-r--r--src/library/scala/reflect/Manifest.scala54
-rw-r--r--src/library/scala/sys/Prop.scala1
7 files changed, 44 insertions, 33 deletions
diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala
index e256a94961..dc8e67bbb0 100644
--- a/src/library/scala/Function1.scala
+++ b/src/library/scala/Function1.scala
@@ -25,6 +25,7 @@ package scala
* }
* }}}
*/
+@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.")
trait Function1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) +R] extends AnyRef { self =>
/** Apply the body of this function to the argument.
* @return the result of function application.
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 61c8ca3f6a..20473009bf 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -12,7 +12,7 @@ import scala.collection.{ mutable, immutable, generic }
import immutable.StringOps
import mutable.ArrayOps
import generic.CanBuildFrom
-import annotation.elidable
+import annotation.{ elidable, implicitNotFound }
import annotation.elidable.ASSERTION
/** The <code>Predef</code> object provides definitions that are
@@ -342,6 +342,7 @@ object Predef extends LowPriorityImplicits {
* where L is the required lower bound).
* in part contributed by Jason Zaugg
*/
+ @implicitNotFound(msg = "Cannot prove that ${From} <:< ${To}.")
sealed abstract class <:<[-From, +To] extends (From => To) with Serializable
implicit def conforms[A]: A <:< A = new (A <:< A) { def apply(x: A) = x }
// not in the <:< companion object because it is also intended to subsume identity (which is no longer implicit)
@@ -350,6 +351,7 @@ object Predef extends LowPriorityImplicits {
*
* @see <:< for expressing subtyping constraints
*/
+ @implicitNotFound(msg = "Cannot prove that ${From} =:= ${To}.")
sealed abstract class =:=[From, To] extends (From => To) with Serializable
object =:= {
implicit def tpEquals[A]: A =:= A = new (A =:= A) {def apply(x: A) = x}
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index 0a2d851b2d..a233e519b3 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -393,7 +393,7 @@ trait TraversableOnce[+A] {
}
def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A = {
if (isEmpty)
- throw new UnsupportedOperationException("empty.maxBy")
+ throw new UnsupportedOperationException("empty.minBy")
reduceLeft((x, y) => if (cmp.lteq(f(x), f(y))) x else y)
}
diff --git a/src/library/scala/math/Ordering.scala b/src/library/scala/math/Ordering.scala
index eeb8c080a1..10e42a6de4 100644
--- a/src/library/scala/math/Ordering.scala
+++ b/src/library/scala/math/Ordering.scala
@@ -30,6 +30,7 @@ import java.util.Comparator
* @version 0.9.5, 2008-04-15
* @since 2.7
*/
+@annotation.implicitNotFound(msg = "No implicit Ordering defined for ${T}.")
trait Ordering[T] extends Comparator[T] with PartialOrdering[T] with Serializable {
outer =>
diff --git a/src/library/scala/reflect/ClassManifest.scala b/src/library/scala/reflect/ClassManifest.scala
index d18cfbc652..3f3892e802 100644
--- a/src/library/scala/reflect/ClassManifest.scala
+++ b/src/library/scala/reflect/ClassManifest.scala
@@ -144,16 +144,10 @@ trait ClassManifest[T] extends OptManifest[T] with Equals with Serializable {
else ""
}
-/** <p>
- * This object is used by the compiler and <b>should not be used in client
- * code</b>. The object Manifest defines factory methods for
- * manifests.
- * </p>
- * <p>
- * <b>BE AWARE</b>: The factory for refinement types is missing and
- * will be implemented in a later version of this class.
- * </p>
- */
+/** The object ClassManifest defines factory methods for manifests.
+ * It is intended for use by the compiler and should not be used
+ * in client code.
+ */
object ClassManifest {
val Byte = Manifest.Byte
val Short = Manifest.Short
diff --git a/src/library/scala/reflect/Manifest.scala b/src/library/scala/reflect/Manifest.scala
index 5545a43740..229fa728a8 100644
--- a/src/library/scala/reflect/Manifest.scala
+++ b/src/library/scala/reflect/Manifest.scala
@@ -10,17 +10,35 @@ package scala.reflect
import scala.collection.mutable.{ ArrayBuilder, WrappedArray }
-/** <p>
- * A <code>Manifest[T]</code> is an opaque descriptor for type <code>T</code>.
- * Currently, its only use is to give access to the erasure of the type as a
- * <code>Class</code> instance.
- * </p>
- * <p>
- * <b>BE AWARE</b>: The different type-relation operators are all forwarded
- * to the erased type as an approximation of the final semantics where
- * these operators should be on the unerased type.
- * </p>
- */
+/** A Manifest[T] is an opaque descriptor for type T. Its
+ * supported use is to give access to the erasure of the type
+ * as a Class instance, as is necessary for the creation of native
+ * Arrays if the class is not known at compile time.
+ *
+ * The type-relation operators <:< and =:= should be considered
+ * approximations only, as there are numerous aspects of type conformance
+ * which are not yet adequately represented in manifests.
+ *
+ * Example usages:
+{{{
+ def arr[T] = new Array[T](0) // does not compile
+ def arr[T](implicit m: Manifest[T]) = new Array[T](0) // compiles
+ def arr[T: Manifest] = new Array[T](0) // shorthand for the preceding
+
+ // Methods manifest, classManifest, and optManifest are in [[scala.Predef]].
+ def isApproxSubType[T: Manifest, U: Manifest] = manifest[T] <:< manifest[U]
+ isApproxSubType[List[String], List[AnyRef]] // true
+ isApproxSubType[List[String], List[Int]] // false
+
+ def methods[T: ClassManifest] = classManifest[T].erasure.getMethods
+ def retType[T: ClassManifest](name: String) =
+ methods[T] find (_.getName == name) map (_.getGenericReturnType)
+
+ retType[Map[_, _]]("values") // Some(scala.collection.Iterable<B>)
+}}}
+ *
+ */
+@annotation.implicitNotFound(msg = "No Manifest available for ${T}.")
trait Manifest[T] extends ClassManifest[T] with Equals {
override def typeArguments: List[Manifest[_]] = Nil
@@ -52,16 +70,10 @@ trait AnyValManifest[T] extends Manifest[T] with Equals {
override def hashCode = System.identityHashCode(this)
}
-/** <ps>
- * This object is used by the compiler and <b>should not be used in client
- * code</b>. The object <code>Manifest</code> defines factory methods for
- * manifests.
- * </p>
- * <p>
- * <b>BE AWARE</b>: The factory for refinement types is missing and
- * will be implemented in a later version of this class.
- * </p>
- */
+/** The object Manifest defines factory methods for manifests.
+ * It is intended for use by the compiler and should not be used
+ * in client code.
+ */
object Manifest {
private def ObjectClass = classOf[java.lang.Object]
diff --git a/src/library/scala/sys/Prop.scala b/src/library/scala/sys/Prop.scala
index de38a56c73..fa866085c0 100644
--- a/src/library/scala/sys/Prop.scala
+++ b/src/library/scala/sys/Prop.scala
@@ -69,6 +69,7 @@ object Prop {
* parameter of type Creator[T] is in scope, a Prop[T] can be created
* via this object's apply method.
*/
+ @annotation.implicitNotFound("No implicit property creator available for type ${T}.")
trait Creator[+T] {
/** Creates a Prop[T] of this type based on the given key. */
def apply(key: String): Prop[T]