diff options
-rw-r--r-- | src/reflect/scala/reflect/api/Exprs.scala | 5 | ||||
-rw-r--r-- | test/files/neg/compile-time-only-b.check | 7 | ||||
-rw-r--r-- | test/files/neg/compile-time-only-b.scala | 15 |
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 |