summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-02-18 14:37:51 +0100
committerEugene Burmako <xeno.by@gmail.com>2014-03-23 12:02:26 +0100
commit3314d76cebc6e27ba4d4ca75cc64fe67fcb90fb6 (patch)
tree3baf8d11bbed829f6ba0b66b03144a46fe05baed /test/files/run
parentb66a39653b9bccab72036ba58fec5fd7d596d313 (diff)
downloadscala-3314d76cebc6e27ba4d4ca75cc64fe67fcb90fb6.tar.gz
scala-3314d76cebc6e27ba4d4ca75cc64fe67fcb90fb6.tar.bz2
scala-3314d76cebc6e27ba4d4ca75cc64fe67fcb90fb6.zip
[nomaster] 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. (cherry picked from commit 609047ba372ceaf06916d3361954bc949a6906ee)
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/typecheck.check0
-rw-r--r--test/files/run/typecheck/Macros_1.scala17
-rw-r--r--test/files/run/typecheck/Test_2.scala15
3 files changed, 32 insertions, 0 deletions
diff --git a/test/files/run/typecheck.check b/test/files/run/typecheck.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/typecheck.check
diff --git a/test/files/run/typecheck/Macros_1.scala b/test/files/run/typecheck/Macros_1.scala
new file mode 100644
index 0000000000..850a611ab1
--- /dev/null
+++ b/test/files/run/typecheck/Macros_1.scala
@@ -0,0 +1,17 @@
+import scala.reflect.macros.Context
+import scala.language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val classDef = ClassDef(
+ Modifiers(), newTypeName("C"), List(),
+ Template(
+ List(Select(Ident(newTermName("scala")), newTypeName("AnyRef"))), emptyValDef,
+ List(DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))))))
+ c.typeCheck(classDef)
+ c.Expr[Any](Literal(Constant(())))
+ }
+
+ 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..0a3279e23e
--- /dev/null
+++ b/test/files/run/typecheck/Test_2.scala
@@ -0,0 +1,15 @@
+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()
+ val classDef = ClassDef(
+ Modifiers(), newTypeName("C"), List(),
+ Template(
+ List(Select(Ident(newTermName("scala")), newTypeName("AnyRef"))), emptyValDef,
+ List(DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))))))
+ tb.typeCheck(classDef)
+} \ No newline at end of file