From 609047ba372ceaf06916d3361954bc949a6906ee Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 12 Feb 2014 12:11:40 +0100 Subject: typecheck(q"class C") no longer crashes MemberDefs alone can't be typechecked as is, because namer only names contents of PackageDefs, Templates and Blocks. And, if not named, a tree can't be typed. This commit solves this problem by wrapping typecheckees in a trivial block and then unwrapping the result when it returns back from the typechecker. --- test/files/run/t7185.check | 4 +--- test/files/run/typecheck.check | 0 test/files/run/typecheck/Macros_1.scala | 12 ++++++++++++ test/files/run/typecheck/Test_2.scala | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/files/run/typecheck.check create mode 100644 test/files/run/typecheck/Macros_1.scala create mode 100644 test/files/run/typecheck/Test_2.scala (limited to 'test/files') diff --git a/test/files/run/t7185.check b/test/files/run/t7185.check index ebf85b731f..2b4adf36b4 100644 --- a/test/files/run/t7185.check +++ b/test/files/run/t7185.check @@ -24,9 +24,7 @@ tree: reflect.runtime.universe.Apply = scala> {val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typecheck(tree): Any} res0: Any = { - { - $read.O.apply() - } + $read.O.apply() } scala> diff --git a/test/files/run/typecheck.check b/test/files/run/typecheck.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/run/typecheck/Macros_1.scala b/test/files/run/typecheck/Macros_1.scala new file mode 100644 index 0000000000..ee1c8da763 --- /dev/null +++ b/test/files/run/typecheck/Macros_1.scala @@ -0,0 +1,12 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +object Macros { + def impl(c: Context) = { + import c.universe._ + c.typecheck(q"class C") + q"()" + } + + def foo: Any = macro impl +} \ No newline at end of file diff --git a/test/files/run/typecheck/Test_2.scala b/test/files/run/typecheck/Test_2.scala new file mode 100644 index 0000000000..01bf5198cc --- /dev/null +++ b/test/files/run/typecheck/Test_2.scala @@ -0,0 +1,10 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + Macros.foo + + val tb = cm.mkToolBox() + tb.typecheck(q"class C") +} \ No newline at end of file -- cgit v1.2.3