diff options
Diffstat (limited to 'test/files/run/showdecl')
-rw-r--r-- | test/files/run/showdecl/Macros_1.scala | 30 | ||||
-rw-r--r-- | test/files/run/showdecl/Test_2.scala | 32 |
2 files changed, 62 insertions, 0 deletions
diff --git a/test/files/run/showdecl/Macros_1.scala b/test/files/run/showdecl/Macros_1.scala new file mode 100644 index 0000000000..c68dd275de --- /dev/null +++ b/test/files/run/showdecl/Macros_1.scala @@ -0,0 +1,30 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +object Macros { + def impl(c: Context) = { + var messages = List[String]() + def println(msg: String) = messages :+= msg + + import c.universe._ + def test(sym: Symbol): Unit = { + println(s"uninitialized ${sym.name}: ${showDecl(sym)}") + sym.info + println(s"initialized ${sym.name}: ${showDecl(sym)}") + } + + println("compile-time") + test(c.mirror.staticClass("D")) + test(c.mirror.staticClass("D").info.member(TermName("x"))) + test(c.mirror.staticClass("D").info.member(TermName("y"))) + test(c.mirror.staticClass("D").info.member(TermName("z"))) + test(c.mirror.staticClass("D").info.member(TermName("t"))) + test(c.mirror.staticClass("D").info.member(TypeName("W"))) + test(c.mirror.staticClass("D").info.member(TypeName("C"))) + test(c.mirror.staticClass("D").info.member(TermName("O"))) + + q"..${messages.map(msg => q"println($msg)")}" + } + + def foo: Any = macro impl +}
\ No newline at end of file diff --git a/test/files/run/showdecl/Test_2.scala b/test/files/run/showdecl/Test_2.scala new file mode 100644 index 0000000000..6eb64baf34 --- /dev/null +++ b/test/files/run/showdecl/Test_2.scala @@ -0,0 +1,32 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + def test(sym: Symbol): Unit = { + println(s"autoinitialized ${sym.name}: ${showDecl(sym)}") + sym.info + println(s"autoinitialized ${sym.name}: ${showDecl(sym)}") + } + + Macros.foo + println("runtime") + test(symbolOf[D]) + test(typeOf[D].member(TermName("x"))) + test(typeOf[D].member(TermName("y"))) + test(typeOf[D].member(TermName("z"))) + test(typeOf[D].member(TermName("t"))) + test(typeOf[D].member(TypeName("W"))) + test(typeOf[D].member(TypeName("C"))) + test(typeOf[D].member(TermName("O"))) +} + +class C +class D extends C { + val x = 2 + lazy val y = 3 + var z = 4 + def t[T <: Int](x: D)(y: x.W) = 5 + type W = String + class C extends D + object O extends C +} |