diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-25 17:55:47 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-26 16:18:28 +0100 |
commit | b9bd441662f1235ecd2f80e13030bfcd4f3c4c39 (patch) | |
tree | 403a019467f9442863a1e42b114de096f363d722 /src/test/scala | |
parent | e2b840b96a16f7d41dc43c3cf6d905e0db568629 (diff) | |
download | scala-async-b9bd441662f1235ecd2f80e13030bfcd4f3c4c39.tar.gz scala-async-b9bd441662f1235ecd2f80e13030bfcd4f3c4c39.tar.bz2 scala-async-b9bd441662f1235ecd2f80e13030bfcd4f3c4c39.zip |
Synthesize an object implementing Function#apply and resume()
There is a fly in the ointment: any This() trees in the provided
code are getting rebound to this class. Sounds like more
resetAttrs fun ahead.
The object also serves as the Future {} thunk.
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 13 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/hygiene/Hygiene.scala | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index ca4a309..4bdb84d 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -30,13 +30,14 @@ class TreeInterrogation { import tb.mirror.universe._ val functions = tree1.collect { case f: Function => f + case t: Template => t } functions.size mustBe 1 val varDefs = tree1.collect { case ValDef(mods, name, _, _) if mods.hasFlag(Flag.MUTABLE) => name } - varDefs.map(_.decoded).toSet mustBe (Set("state$async", "onCompleteHandler$async", "await$1", "await$2")) + varDefs.map(_.decoded.trim).toSet mustBe (Set("state$async", "await$1", "await$2")) } } @@ -56,7 +57,15 @@ object TreeInterrogation extends App { val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:all") val tree = tb.parse( """ import _root_.scala.async.AsyncId._ - | async { val a = 0; val x = await(a) - 1; def foo(z: Any) = (a.toDouble, x.toDouble, z); foo(await(2)) } + | object Test { + | def blerg = 1 + | def check() { + | async { + | assert(this.blerg == 1) + | assert(this == Test, this.getClass) + | } + | } + | } | """.stripMargin) println(tree) val tree1 = tb.typeCheck(tree.duplicate) diff --git a/src/test/scala/scala/async/run/hygiene/Hygiene.scala b/src/test/scala/scala/async/run/hygiene/Hygiene.scala index 0da2a4d..2aaf515 100644 --- a/src/test/scala/scala/async/run/hygiene/Hygiene.scala +++ b/src/test/scala/scala/async/run/hygiene/Hygiene.scala @@ -87,4 +87,17 @@ class HygieneSpec { } ext mustBe (14) } + +// @Test def `this reference is maintained`() { +// object Test { +// def blerg = 1 +// def check() { +// AsyncId.async { +// assert(this.blerg == 1) +// assert(this == Test, this.getClass) +// } +// } +// } +// Test.check() +// } } |