diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-08-10 00:33:30 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-08-13 21:03:29 +0200 |
commit | 46aab7b8d77d275aad0686b11214ee1a0d62e941 (patch) | |
tree | bb4fde5db2cb8cb3be7253db513c5fce02a8bcc6 /test | |
parent | 64138082a4f1bb4c864d85660d350f61c81e7fd7 (diff) | |
download | scala-46aab7b8d77d275aad0686b11214ee1a0d62e941.tar.gz scala-46aab7b8d77d275aad0686b11214ee1a0d62e941.tar.bz2 scala-46aab7b8d77d275aad0686b11214ee1a0d62e941.zip |
macro implementations must be public
The immediate motivator for this change was the desire to keep things simple
during macro expansion.
Here's the story. When you expand a macro, you need to reflectively load
a macro implementation method and invoke it. However private methods in Scala
can sometime have their names mangled, so the reflector has to check multiple
variants of the same name (the normal one and the mangled one).
The problem is that since the previous commit we don't have an access to a
symbol of the macro impl, hence we cannot just use `impl.expandedName` like
we did before. Sure I could duplicate the logic of expandedName, but I have
a better suggestion.
Let's prohibit non-public macro implementations. This doesn't seem to hurt,
and it lets us avoid extra bit of complexity in Macros.scala.
If this measure turns out to be a hassle during the trial period of macros,
non-public macros can always be allowed. In fact, we can even have this feature
back for free when we migrate from Java reflection to Scala reflection for
invoking macro implementations (because Scala reflection knows how to account
for mangled private names). But that's the 2.10.x business.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/macro-invalidimpl-i.check | 4 | ||||
-rw-r--r-- | test/files/neg/macro-invalidimpl-i.flags | 1 | ||||
-rw-r--r-- | test/files/neg/macro-invalidimpl-i/Impls_1.scala | 7 | ||||
-rw-r--r-- | test/files/neg/macro-invalidimpl-i/Macros_Test_2.scala | 5 |
4 files changed, 17 insertions, 0 deletions
diff --git a/test/files/neg/macro-invalidimpl-i.check b/test/files/neg/macro-invalidimpl-i.check new file mode 100644 index 0000000000..b6277809a3 --- /dev/null +++ b/test/files/neg/macro-invalidimpl-i.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:4: error: macro implementation must be public
+ def foo = macro Impls.impl
+ ^
+one error found
diff --git a/test/files/neg/macro-invalidimpl-i.flags b/test/files/neg/macro-invalidimpl-i.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/neg/macro-invalidimpl-i.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/neg/macro-invalidimpl-i/Impls_1.scala b/test/files/neg/macro-invalidimpl-i/Impls_1.scala new file mode 100644 index 0000000000..c35d8ab3c1 --- /dev/null +++ b/test/files/neg/macro-invalidimpl-i/Impls_1.scala @@ -0,0 +1,7 @@ +package foo + +import scala.reflect.macros.Context + +object Impls { + private[foo] def impl(c: Context) = ??? +}
\ No newline at end of file diff --git a/test/files/neg/macro-invalidimpl-i/Macros_Test_2.scala b/test/files/neg/macro-invalidimpl-i/Macros_Test_2.scala new file mode 100644 index 0000000000..fb129c70be --- /dev/null +++ b/test/files/neg/macro-invalidimpl-i/Macros_Test_2.scala @@ -0,0 +1,5 @@ +package foo + +object Test extends App { + def foo = macro Impls.impl +} |