diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-11-29 12:00:46 -0800 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-11-29 12:00:46 -0800 |
commit | f16f4ab157293ac6860d4b00578b983c90b8fc62 (patch) | |
tree | feb4f2532dd7cae101796cc0c78c411923ff5282 | |
parent | b149c7b5f26b6771557849aa04b96a3ca3bdedee (diff) | |
parent | 1be02447823f309c7450299ba7128da4b86573ad (diff) | |
download | scala-f16f4ab157293ac6860d4b00578b983c90b8fc62.tar.gz scala-f16f4ab157293ac6860d4b00578b983c90b8fc62.tar.bz2 scala-f16f4ab157293ac6860d4b00578b983c90b8fc62.zip |
Merge pull request #1678 from martende/ticket/5753
SI-5753 macros cannot be loaded when inherited from a class or a trait
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Macros.scala | 13 | ||||
-rw-r--r-- | test/files/neg/t5753.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5753.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t5753/Impls$class.class | bin | 0 -> 626 bytes | |||
-rw-r--r-- | test/files/neg/t5753/Impls.class | bin | 0 -> 866 bytes | |||
-rw-r--r-- | test/files/neg/t5753/Impls_Macros_1.scala | 6 | ||||
-rw-r--r-- | test/files/neg/t5753/Test_2.scala | 11 | ||||
-rw-r--r-- | test/files/run/t5753_1.check | 1 | ||||
-rw-r--r-- | test/files/run/t5753_1.flags | 1 | ||||
-rw-r--r-- | test/files/run/t5753_1/Impls_Macros_1.scala | 10 | ||||
-rw-r--r-- | test/files/run/t5753_1/Test_2.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5753_2.check | 1 | ||||
-rw-r--r-- | test/files/run/t5753_2.flags | 1 | ||||
-rw-r--r-- | test/files/run/t5753_2/Impls_Macros_1.scala | 10 | ||||
-rw-r--r-- | test/files/run/t5753_2/Test_2.scala | 4 |
15 files changed, 57 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index bcc37e8b37..b20a9ea626 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -122,16 +122,9 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } def pickle(macroImplRef: Tree): Tree = { - val macroImpl = macroImplRef.symbol + val MacroImplReference(owner, macroImpl, targs) = macroImplRef val paramss = macroImpl.paramss - // this logic relies on the assumptions that were valid for the old macro prototype - // namely that macro implementations can only be defined in top-level classes and modules - // with the new prototype that materialized in a SIP, macros need to be statically accessible, which is different - // for example, a macro def could be defined in a trait that is implemented by an object - // there are some more clever cases when seemingly non-static method ends up being statically accessible - // however, the code below doesn't account for these guys, because it'd take a look of time to get it right - // for now I leave it as a todo and move along to more the important stuff // todo. refactor when fixing SI-5498 def className: String = { def loop(sym: Symbol): String = sym match { @@ -143,7 +136,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { loop(sym.owner) + separator + sym.javaSimpleName.toString } - loop(macroImpl.owner.enclClass) + loop(owner) } def signature: List[Int] = { @@ -164,7 +157,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { // I just named it "macro", because it's macro-related, but I could as well name it "foobar" val nucleus = Ident(newTermName("macro")) val wrapped = Apply(nucleus, payload map { case (k, v) => Assign(pickleAtom(k), pickleAtom(v)) }) - val pickle = gen.mkTypeApply(wrapped, treeInfo.typeArguments(macroImplRef.duplicate)) + val pickle = gen.mkTypeApply(wrapped, targs map (_.duplicate)) // assign NoType to all freshly created AST nodes // otherwise pickler will choke on tree.tpe being null diff --git a/test/files/neg/t5753.check b/test/files/neg/t5753.check new file mode 100644 index 0000000000..76602de17d --- /dev/null +++ b/test/files/neg/t5753.check @@ -0,0 +1,4 @@ +Test_2.scala:9: error: macro implementation not found: foo (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) + println(foo(42)) + ^ +one error found diff --git a/test/files/neg/t5753.flags b/test/files/neg/t5753.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/neg/t5753.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/neg/t5753/Impls$class.class b/test/files/neg/t5753/Impls$class.class Binary files differnew file mode 100644 index 0000000000..476329174e --- /dev/null +++ b/test/files/neg/t5753/Impls$class.class diff --git a/test/files/neg/t5753/Impls.class b/test/files/neg/t5753/Impls.class Binary files differnew file mode 100644 index 0000000000..dfcf89ed44 --- /dev/null +++ b/test/files/neg/t5753/Impls.class diff --git a/test/files/neg/t5753/Impls_Macros_1.scala b/test/files/neg/t5753/Impls_Macros_1.scala new file mode 100644 index 0000000000..1d9c26458c --- /dev/null +++ b/test/files/neg/t5753/Impls_Macros_1.scala @@ -0,0 +1,6 @@ +import scala.reflect.macros.{Context => Ctx} + +trait Impls { +def impl(c: Ctx)(x: c.Expr[Any]) = x +} + diff --git a/test/files/neg/t5753/Test_2.scala b/test/files/neg/t5753/Test_2.scala new file mode 100644 index 0000000000..2369b18e76 --- /dev/null +++ b/test/files/neg/t5753/Test_2.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.{Context => Ctx} + +object Macros extends Impls { + def foo(x: Any) = macro impl +} + +object Test extends App { + import Macros._ + println(foo(42)) +} + diff --git a/test/files/run/t5753_1.check b/test/files/run/t5753_1.check new file mode 100644 index 0000000000..f70d7bba4a --- /dev/null +++ b/test/files/run/t5753_1.check @@ -0,0 +1 @@ +42
\ No newline at end of file diff --git a/test/files/run/t5753_1.flags b/test/files/run/t5753_1.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/t5753_1.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/run/t5753_1/Impls_Macros_1.scala b/test/files/run/t5753_1/Impls_Macros_1.scala new file mode 100644 index 0000000000..1664301f5f --- /dev/null +++ b/test/files/run/t5753_1/Impls_Macros_1.scala @@ -0,0 +1,10 @@ +import scala.reflect.macros.Context +import language.experimental.macros + +trait Impls { + def impl(c: Context)(x: c.Expr[Any]) = x +} + +object Macros extends Impls { + def foo(x: Any) = macro impl +}
\ No newline at end of file diff --git a/test/files/run/t5753_1/Test_2.scala b/test/files/run/t5753_1/Test_2.scala new file mode 100644 index 0000000000..a2777638bc --- /dev/null +++ b/test/files/run/t5753_1/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + println(foo(42)) +}
\ No newline at end of file diff --git a/test/files/run/t5753_2.check b/test/files/run/t5753_2.check new file mode 100644 index 0000000000..f70d7bba4a --- /dev/null +++ b/test/files/run/t5753_2.check @@ -0,0 +1 @@ +42
\ No newline at end of file diff --git a/test/files/run/t5753_2.flags b/test/files/run/t5753_2.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/t5753_2.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/run/t5753_2/Impls_Macros_1.scala b/test/files/run/t5753_2/Impls_Macros_1.scala new file mode 100644 index 0000000000..e23c0b938b --- /dev/null +++ b/test/files/run/t5753_2/Impls_Macros_1.scala @@ -0,0 +1,10 @@ +import scala.reflect.macros.{Context => Ctx} + +trait Macro_T { + def foo[T](c: Ctx)(s: c.Expr[T]) = s +} + +object Macros { + def foo[T](s: T) = macro Impls.foo[T] + object Impls extends Macro_T +} diff --git a/test/files/run/t5753_2/Test_2.scala b/test/files/run/t5753_2/Test_2.scala new file mode 100644 index 0000000000..a2777638bc --- /dev/null +++ b/test/files/run/t5753_2/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + println(foo(42)) +}
\ No newline at end of file |