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/files/run/reify_classfileann_a.scala | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/files/run/reify_classfileann_a.scala (limited to 'test/files/run/reify_classfileann_a.scala') diff --git a/test/files/run/reify_classfileann_a.scala b/test/files/run/reify_classfileann_a.scala new file mode 100644 index 0000000000..6bf4750bbc --- /dev/null +++ b/test/files/run/reify_classfileann_a.scala @@ -0,0 +1,24 @@ +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{ + @ann(bar="1", quux=Array("2", "3"), baz = new ann(bar = "4")) class C + }.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 -- cgit v1.2.3