summaryrefslogtreecommitdiff
path: root/test/files/neg/macro-invalidret
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-08 16:28:41 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-12-10 10:29:02 +0100
commit87979ad96f3a07354be4c15cdf35f71d1d4739cb (patch)
treeaca34d4bec9a31a44c1a81d18a4701ef8ceb4231 /test/files/neg/macro-invalidret
parent75cc6cf256df9e152eaec771121ce0db9f7039f8 (diff)
downloadscala-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-invalidret')
-rw-r--r--test/files/neg/macro-invalidret/Impls_1.scala3
-rw-r--r--test/files/neg/macro-invalidret/Macros_Test_2.scala8
2 files changed, 11 insertions, 0 deletions
diff --git a/test/files/neg/macro-invalidret/Impls_1.scala b/test/files/neg/macro-invalidret/Impls_1.scala
index d957b74512..b32463899e 100644
--- a/test/files/neg/macro-invalidret/Impls_1.scala
+++ b/test/files/neg/macro-invalidret/Impls_1.scala
@@ -4,4 +4,7 @@ import scala.reflect.runtime.{universe => ru}
object Impls {
def foo1(c: BlackboxContext) = 2
def foo2(c: BlackboxContext) = ru.Literal(ru.Constant(42))
+ def foo3(c: BlackboxContext) = ???
+ def foo5(c: BlackboxContext) = c.universe.Literal(c.universe.Constant(42))
+ def foo6(c: BlackboxContext) = c.Expr[Int](c.universe.Literal(c.universe.Constant(42)))
}
diff --git a/test/files/neg/macro-invalidret/Macros_Test_2.scala b/test/files/neg/macro-invalidret/Macros_Test_2.scala
index f8880fa023..8840f492ab 100644
--- a/test/files/neg/macro-invalidret/Macros_Test_2.scala
+++ b/test/files/neg/macro-invalidret/Macros_Test_2.scala
@@ -1,10 +1,18 @@
object Macros {
def foo1 = macro Impls.foo1
def foo2 = macro Impls.foo2
+ def foo3 = macro Impls.foo3
+ def foo4 = macro ???
+ def foo5 = macro Impls.foo5
+ def foo6 = macro Impls.foo6
}
object Test extends App {
import Macros._
foo1
foo2
+ foo3
+ foo4
+ foo5
+ foo6
} \ No newline at end of file