From 6548dcf12d83e327df2f90048140fb95346b7e95 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 12 Feb 2012 23:07:30 +0100 Subject: reifyAnnotations Annotations are now supported by the reifier: * AnnotationInfos from symbols get transformed back into mods. * AnnotatedTypes are retained and are reified along with AnnotationInfos. Reification is no magic, and reification of annotations especially: * Annotations cannot refer to symbols defined inside the quasiquote. This restriction is due to the fact that we need to erase locally defined symbols before reifying to make subsequent reflective compilations succeed. However, while doing that, we also need to make sure that we don't make resulting ASTs non-compilable by removing essential information. This is tricky, and it more or less works for TypeTrees, but not for annotations that can contain arbitrary ASTs. For more details look into the comments to Reifiers.scala. * Classfile annotations that contain array arguments and are applied to types, i.e. the ones that generate AnnotatedTypes, cannot be reified. This is because of limitations of manifest infrastructure. Typechecking "Array(mirror.LiteralAnnotArg(...))" would require the compiler to produce a manifest for a path-dependent type, which cannot be done now. Review by @odersky. --- test/pending/run/reify_classfileann_b.check | 0 test/pending/run/reify_classfileann_b.scala | 28 ++++++++++++++++++++++++++++ test/pending/run/t5224.check | 9 --------- test/pending/run/t5224.scala | 8 -------- test/pending/run/t5225_1.check | 4 ---- test/pending/run/t5225_1.scala | 8 -------- test/pending/run/t5225_2.check | 4 ---- test/pending/run/t5225_2.scala | 8 -------- 8 files changed, 28 insertions(+), 41 deletions(-) create mode 100644 test/pending/run/reify_classfileann_b.check create mode 100644 test/pending/run/reify_classfileann_b.scala delete mode 100644 test/pending/run/t5224.check delete mode 100644 test/pending/run/t5224.scala delete mode 100644 test/pending/run/t5225_1.check delete mode 100644 test/pending/run/t5225_1.scala delete mode 100644 test/pending/run/t5225_2.check delete mode 100644 test/pending/run/t5225_2.scala (limited to 'test/pending') diff --git a/test/pending/run/reify_classfileann_b.check b/test/pending/run/reify_classfileann_b.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/pending/run/reify_classfileann_b.scala b/test/pending/run/reify_classfileann_b.scala new file mode 100644 index 0000000000..b76dd8fc9f --- /dev/null +++ b/test/pending/run/reify_classfileann_b.scala @@ -0,0 +1,28 @@ +import scala.reflect._ +import scala.reflect.api._ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +class ann(bar: String, quux: Array[String] = Array(), baz: ann = null) extends ClassfileAnnotation + +object Test extends App { + // test 1: reify + val tree = scala.reflect.Code.lift{ + class C { + def x: Int = { + 2: @ann(bar="1", quux=Array("2", "3"), baz = new ann(bar = "4")) + } + } + }.tree + println(tree.toString) + + // test 2: import and typecheck + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(tree) + println(ttree.toString) + + // test 3: import and compile + toolbox.runExpr(ttree) +} \ No newline at end of file diff --git a/test/pending/run/t5224.check b/test/pending/run/t5224.check deleted file mode 100644 index 2b920773c0..0000000000 --- a/test/pending/run/t5224.check +++ /dev/null @@ -1,9 +0,0 @@ -{ - @serializable class C extends Object with ScalaObject { - def () = { - super.(); - () - } - }; - () -} \ No newline at end of file diff --git a/test/pending/run/t5224.scala b/test/pending/run/t5224.scala deleted file mode 100644 index 865ce4bfe9..0000000000 --- a/test/pending/run/t5224.scala +++ /dev/null @@ -1,8 +0,0 @@ -import scala.reflect._ -import scala.reflect.api._ - -object Test extends App { - println(scala.reflect.Code.lift{ - @serializable class C - }.tree.toString) -} \ No newline at end of file diff --git a/test/pending/run/t5225_1.check b/test/pending/run/t5225_1.check deleted file mode 100644 index b29cd9c365..0000000000 --- a/test/pending/run/t5225_1.check +++ /dev/null @@ -1,4 +0,0 @@ -{ - @transient @volatile var x: Int = 2; - () -} \ No newline at end of file diff --git a/test/pending/run/t5225_1.scala b/test/pending/run/t5225_1.scala deleted file mode 100644 index 454502e810..0000000000 --- a/test/pending/run/t5225_1.scala +++ /dev/null @@ -1,8 +0,0 @@ -import scala.reflect._ -import scala.reflect.api._ - -object Test extends App { - println(scala.reflect.Code.lift{ - @transient @volatile var x = 2 - }.tree.toString) -} \ No newline at end of file diff --git a/test/pending/run/t5225_2.check b/test/pending/run/t5225_2.check deleted file mode 100644 index 88972fd27f..0000000000 --- a/test/pending/run/t5225_2.check +++ /dev/null @@ -1,4 +0,0 @@ -{ - def foo(@cloneable x: Int): String = ""; - () -} diff --git a/test/pending/run/t5225_2.scala b/test/pending/run/t5225_2.scala deleted file mode 100644 index 82bad0f353..0000000000 --- a/test/pending/run/t5225_2.scala +++ /dev/null @@ -1,8 +0,0 @@ -import scala.reflect._ -import scala.reflect.api._ - -object Test extends App { - println(scala.reflect.Code.lift{ - def foo(@cloneable x: Int) = "" - }.tree.toString) -} \ No newline at end of file -- cgit v1.2.3