From a2b523a39b4e56eb9ab5d9a5639f5b59d425e354 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 17:21:27 +0200 Subject: blackbox restriction #1: can't refine the official return type When an application of a blackbox macro expands into a tree `x`, the expansion is wrapped into a type ascription `(x: T)`, where `T` is the declared return type of the blackbox macro with type arguments and path dependencies applied in consistency with the particular macro application being expanded. This invalidates blackbox macros as an implementation vehicle of type providers. --- test/files/neg/macro-blackbox-structural.check | 4 ++++ .../neg/macro-blackbox-structural/Impls_Macros_1.scala | 15 +++++++++++++++ test/files/neg/macro-blackbox-structural/Test_2.scala | 5 +++++ test/files/neg/t5903a/Macros_1.scala | 4 ++-- test/files/neg/t5903e/Macros_1.scala | 4 ++-- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/files/neg/macro-blackbox-structural.check create mode 100644 test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala create mode 100644 test/files/neg/macro-blackbox-structural/Test_2.scala (limited to 'test/files/neg') diff --git a/test/files/neg/macro-blackbox-structural.check b/test/files/neg/macro-blackbox-structural.check new file mode 100644 index 0000000000..86a218559c --- /dev/null +++ b/test/files/neg/macro-blackbox-structural.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: value x is not a member of Any + println(Macros.foo.x) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala b/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala new file mode 100644 index 0000000000..08f1c21e89 --- /dev/null +++ b/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala @@ -0,0 +1,15 @@ +import scala.language.experimental.macros + +object Macros { + def impl(c: scala.reflect.macros.BlackboxContext) = { + import c.universe._ + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-structural/Test_2.scala b/test/files/neg/macro-blackbox-structural/Test_2.scala new file mode 100644 index 0000000000..ea6a817e34 --- /dev/null +++ b/test/files/neg/macro-blackbox-structural/Test_2.scala @@ -0,0 +1,5 @@ +import Macros._ + +object Test extends App { + println(Macros.foo.x) +} \ No newline at end of file diff --git a/test/files/neg/t5903a/Macros_1.scala b/test/files/neg/t5903a/Macros_1.scala index 9fc3bfe261..7888b888e1 100644 --- a/test/files/neg/t5903a/Macros_1.scala +++ b/test/files/neg/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/neg/t5903e/Macros_1.scala b/test/files/neg/t5903e/Macros_1.scala index 13e168d529..997e6fd073 100644 --- a/test/files/neg/t5903e/Macros_1.scala +++ b/test/files/neg/t5903e/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { -- cgit v1.2.3