summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-08-10 14:52:24 +0200
committerEugene Burmako <xeno.by@gmail.com>2013-08-15 08:06:22 +0200
commit840ad7656456f014135c2a5e31e0d9ffd63625bd (patch)
treee3333eae1e5db6457638ba6455efebd1f54d8ca5
parent1b5f73129fc2f678d00905e5d851536251f8821a (diff)
downloadscala-840ad7656456f014135c2a5e31e0d9ffd63625bd.tar.gz
scala-840ad7656456f014135c2a5e31e0d9ffd63625bd.tar.bz2
scala-840ad7656456f014135c2a5e31e0d9ffd63625bd.zip
marks Expr.splice and Expr.value with @compileTimeOnly
Now that @compileTimeOnly is part of the standard library, why don't we use it within the standard library.
-rw-r--r--src/reflect/scala/reflect/api/Exprs.scala5
-rw-r--r--test/files/neg/compile-time-only-b.check7
-rw-r--r--test/files/neg/compile-time-only-b.scala15
3 files changed, 25 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/api/Exprs.scala b/src/reflect/scala/reflect/api/Exprs.scala
index 009d9dbfdb..5b6ff2325c 100644
--- a/src/reflect/scala/reflect/api/Exprs.scala
+++ b/src/reflect/scala/reflect/api/Exprs.scala
@@ -8,6 +8,7 @@ package reflect
package api
import scala.reflect.runtime.{universe => ru}
+import scala.annotation.compileTimeOnly
/**
* <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
@@ -91,7 +92,7 @@ trait Exprs { self: Universe =>
* }}}
* because expr of type Expr[T] itself does not have a method foo.
*/
- // @compileTimeOnly("Cannot use splice outside reify")
+ @compileTimeOnly("splice must be enclosed within a reify {} block")
def splice: T
/**
@@ -108,7 +109,7 @@ trait Exprs { self: Universe =>
* object Impls { def foo_impl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ... }
* }}}
*/
- // @compileTimeOnly("Cannot use value except for signatures of macro implementations")
+ @compileTimeOnly("cannot use value except for signatures of macro implementations")
val value: T
override def canEqual(x: Any) = x.isInstanceOf[Expr[_]]
diff --git a/test/files/neg/compile-time-only-b.check b/test/files/neg/compile-time-only-b.check
new file mode 100644
index 0000000000..8292a0ddeb
--- /dev/null
+++ b/test/files/neg/compile-time-only-b.check
@@ -0,0 +1,7 @@
+compile-time-only-b.scala:13: error: splice must be enclosed within a reify {} block
+ val ignored3 = reify(fortyTwo).splice
+ ^
+compile-time-only-b.scala:14: error: cannot use value except for signatures of macro implementations
+ val ignored4 = reify(fortyTwo).value
+ ^
+two errors found
diff --git a/test/files/neg/compile-time-only-b.scala b/test/files/neg/compile-time-only-b.scala
new file mode 100644
index 0000000000..d5568dbe67
--- /dev/null
+++ b/test/files/neg/compile-time-only-b.scala
@@ -0,0 +1,15 @@
+import scala.reflect.runtime.universe._
+
+object Test extends App {
+ // HAHA!!!
+ // no compileTimeOnly errors here, because scalac does constant folding
+ // the type of reify(42) is Expr[42.type]
+ // therefore the type of expr.splice is 42.type, which is then constfolded
+ val expr = reify(42)
+ val ignored1 = expr.splice
+ val ignored2 = expr.value
+
+ val fortyTwo = 42
+ val ignored3 = reify(fortyTwo).splice
+ val ignored4 = reify(fortyTwo).value
+} \ No newline at end of file