From 6c3c0f0a37d337aa297f5b2481d4727ea2a20434 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 26 Nov 2012 17:01:15 +0100 Subject: Show that indirectly nested defs aren't lifted. --- src/test/scala/scala/async/TreeInterrogation.scala | 17 ++++++++++++++++- src/test/scala/scala/async/package.scala | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index 9a31337..a46eaf2 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -8,6 +8,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.junit.Test import AsyncId._ +import tools.reflect.ToolBox @RunWith(classOf[JUnit4]) class TreeInterrogation { @@ -20,14 +21,16 @@ class TreeInterrogation { | async { | val x = await(1) | val y = x * 2 + | def foo(a: Int) = { def nested = 0; a } // don't lift `nested`. | val z = await(x * 3) + | foo(z) | z | }""".stripMargin) val tree1 = tb.typeCheck(tree) //println(cm.universe.show(tree1)) - import tb.mirror.universe._ + import tb.u._ val functions = tree1.collect { case f: Function => f case t: Template => t @@ -38,6 +41,18 @@ class TreeInterrogation { case ValDef(mods, name, _, _) if mods.hasFlag(Flag.MUTABLE) => name } varDefs.map(_.decoded.trim).toSet mustBe (Set("state$async", "await$1", "await$2")) + varDefs.map(_.decoded.trim).toSet mustBe (Set("state$async", "await$1", "await$2")) + + val defDefs = tree1.collect { + case t: Template => + val stats: List[Tree] = t.body + stats.collect { + case dd : DefDef + if !dd.symbol.isImplementationArtifact + && !dd.symbol.asTerm.isAccessor && !dd.symbol.asTerm.isSetter => dd.name + } + }.flatten + defDefs.map(_.decoded.trim).toSet mustBe (Set("foo$1", "apply", "resume$async", "")) } } diff --git a/src/test/scala/scala/async/package.scala b/src/test/scala/scala/async/package.scala index bc4ebac..4a7a958 100644 --- a/src/test/scala/scala/async/package.scala +++ b/src/test/scala/scala/async/package.scala @@ -5,7 +5,7 @@ package scala import reflect._ -import tools.reflect.ToolBoxError +import tools.reflect.{ToolBox, ToolBoxError} package object async { @@ -36,7 +36,7 @@ package object async { tb.eval(tb.parse(code)) } - def mkToolbox(compileOptions: String = "") = { + def mkToolbox(compileOptions: String = ""): ToolBox[_ <: scala.reflect.api.Universe] = { val m = scala.reflect.runtime.currentMirror import scala.tools.reflect.ToolBox m.mkToolBox(options = compileOptions) -- cgit v1.2.3