diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-12-08 16:28:41 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-12-10 10:29:02 +0100 |
commit | 87979ad96f3a07354be4c15cdf35f71d1d4739cb (patch) | |
tree | aca34d4bec9a31a44c1a81d18a4701ef8ceb4231 /test/files/neg/macro-invalidsig.check | |
parent | 75cc6cf256df9e152eaec771121ce0db9f7039f8 (diff) | |
download | scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.tar.gz scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.tar.bz2 scala-87979ad96f3a07354be4c15cdf35f71d1d4739cb.zip |
deprecates macro def return type inference
With the new focus on quasiquotes in macro implementations, we now have
to change the way how inference of macro def return types works.
Previously, if the return type of a macro def wasn’t specified, we looked into
the signature of its macro impl, took its return type (which could only
be c.Expr[T]) and then assigned T to be the return type of the macro def.
We also had a convenient special case which inferred Any in case when
the body of the macro impl wasn’t an expr. That avoided reporting spurious
errors if the macro impl had its body typed incorrectly (because in that
case we would report a def/impl signature mismatch anyway) and also provided
a convenience by letting macro impls end with `???`.
However now we also allow macro impls to return c.Tree, which means that
we are no longer able to do any meaningful type inference, because c.Tree
could correspond to tree of any type.
Unfortunately, when coupled with the type inference special case described
above, this means that the users who migrate from exprs to quasiquotes
are going to face an unpleasant surprise. If they haven’t provided
explicit return types for their macro defs, those types are going to be
silently inferred as `Any`!
This commit plugs this loophole by prohibiting type inference from
non-expr return types of macro impls (not counting Nothing). Moreover,
it also deprecates c.Expr[T] => T inference in order to avoid confusion
when switching between exprs and quasiquotes.
Diffstat (limited to 'test/files/neg/macro-invalidsig.check')
-rw-r--r-- | test/files/neg/macro-invalidsig.check | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/test/files/neg/macro-invalidsig.check b/test/files/neg/macro-invalidsig.check index e09d46146d..5ff4ed18cb 100644 --- a/test/files/neg/macro-invalidsig.check +++ b/test/files/neg/macro-invalidsig.check @@ -1,29 +1,29 @@ Macros_Test_2.scala:2: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences - def foo[U] = macro Impls1.foo[U] - ^ + def foo[U]: Int = macro Impls1.foo[U] + ^ Macros_Test_2.scala:6: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : : Nothing number of parameter sections differ def foo = macro Impls2.foo ^ Macros_Test_2.scala:10: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : (c: scala.reflect.api.Universe): Nothing type mismatch for parameter c: scala.reflect.macros.BlackboxContext does not conform to scala.reflect.api.Universe def foo = macro Impls3.foo ^ Macros_Test_2.scala:14: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : (cs: scala.reflect.macros.BlackboxContext*): Nothing types incompatible for parameter cs: corresponding is not a vararg parameter def foo = macro Impls4.foo ^ Macros_Test_2.scala:18: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any]): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any]): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.BlackboxContext): Nothing number of parameter sections differ @@ -33,35 +33,35 @@ Macros_Test_2.scala:22: error: macro implementations cannot have implicit parame def foo[U](x: Int) = macro Impls6.foo[T, U] ^ Macros_Test_2.scala:26: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): Nothing parameter lists have different length, found extra parameter y: c.Expr[Int] def foo(x: Int) = macro Impls7.foo ^ Macros_Test_2.scala:30: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree found : (c: scala.reflect.macros.BlackboxContext)(x: c.universe.Symbol): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Symbol def foo(x: Int) = macro Impls8.foo ^ Macros_Test_2.scala:34: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree, y: c.Tree): c.Tree found : (c: scala.reflect.macros.BlackboxContext)(xs: c.Expr[Int]*): Nothing parameter lists have different length, required extra parameter y: c.Expr[Int] def foo(x: Int, y: Int) = macro Impls9.foo ^ Macros_Test_2.scala:38: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree, y: c.Tree): c.Tree found : (c: scala.reflect.macros.BlackboxContext)(y: c.Expr[Int], x: c.Expr[Int]): Nothing parameter names differ: x != y def foo(x: Int, y: Int) = macro Impls10.foo ^ Macros_Test_2.scala:42: error: macro implementation has incompatible shape: - required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Nothing] or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : (c: scala.reflect.macros.BlackboxContext)(U: c.universe.Type): Nothing number of parameter sections differ @@ -77,9 +77,9 @@ Macros_Test_2.scala:54: error: macro implementation reference has too few type a def foo = macro Impls14.foo ^ Macros_Test_2.scala:59: error: macro implementation reference has too few type arguments for method foo: [T, U, V](c: scala.reflect.macros.BlackboxContext)(implicit evidence$5: c.WeakTypeTag[T], implicit evidence$6: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] - def foo15[V] = macro Impls15.foo - ^ + def foo15[V]: Unit = macro Impls15.foo + ^ Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.BlackboxContext)(implicit evidence$7: c.WeakTypeTag[T], implicit evidence$8: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] - def foo16[V] = macro Impls16.foo[V] - ^ + def foo16[V]: Unit = macro Impls16.foo[V] + ^ 16 errors found |