diff options
author | Philipp Haller <hallerp@gmail.com> | 2013-04-17 05:35:14 -0700 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2013-04-17 05:35:14 -0700 |
commit | 757930193a0a2225f4c5f35f449615a81d3aaf19 (patch) | |
tree | 3ffc5eb7a469e196ae3e7f74072c6d4e96ba7dcd /src/test/scala | |
parent | c26ba9db06a88dcd384e7dd1f0450206eef6f064 (diff) | |
parent | b38f991ab4948f3358a937604dc28ffa4901270e (diff) | |
download | scala-async-757930193a0a2225f4c5f35f449615a81d3aaf19.tar.gz scala-async-757930193a0a2225f4c5f35f449615a81d3aaf19.tar.bz2 scala-async-757930193a0a2225f4c5f35f449615a81d3aaf19.zip |
Merge pull request #9 from retronym/ticket/4-multi-param
Allow await in applications with multiple argument lists
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/scala/async/TreeInterrogation.scala | 17 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/anf/AnfTransformSpec.scala | 76 |
2 files changed, 65 insertions, 28 deletions
diff --git a/src/test/scala/scala/async/TreeInterrogation.scala b/src/test/scala/scala/async/TreeInterrogation.scala index 4d611e5..deaee03 100644 --- a/src/test/scala/scala/async/TreeInterrogation.scala +++ b/src/test/scala/scala/async/TreeInterrogation.scala @@ -71,17 +71,14 @@ object TreeInterrogation extends App { val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:flatten") import scala.async.Async._ val tree = tb.parse( - """ import scala.async.AsyncId._ - | async { - | val x = 1 - | val opt = Some("") - | await(0) - | val o @ Some(y) = opt - | - | { - | val o @ Some(y) = Some(".") - | } + """ import _root_.scala.async.AsyncId.{async, await} + | def foo[T](a0: Int)(b0: Int*) = s"a0 = $a0, b0 = ${b0.head}" + | val res = async { + | var i = 0 + | def get = async {i += 1; i} + | foo[Int](await(get))(await(get) :: Nil : _*) | } + | res | """.stripMargin) println(tree) val tree1 = tb.typeCheck(tree.duplicate) diff --git a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala index 41c13e0..7be6299 100644 --- a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala +++ b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala @@ -232,28 +232,68 @@ class AnfTransformSpec { } @Test - def awaitNotAllowedInNonPrimaryParamSection1() { - expectError("implementation restriction: await may only be used in the first parameter list.") { - """ - | import _root_.scala.async.AsyncId.{async, await} - | def foo(primary: Any)(i: Int) = i - | async { - | foo(???)(await(0)) - | } - """.stripMargin + def awaitInNonPrimaryParamSection1() { + import _root_.scala.async.AsyncId.{async, await} + def foo(a0: Int)(b0: Int) = s"a0 = $a0, b0 = $b0" + val res = async { + var i = 0 + def get = {i += 1; i} + foo(get)(get) + } + res mustBe "a0 = 1, b0 = 2" + } + + @Test + def awaitInNonPrimaryParamSection2() { + import _root_.scala.async.AsyncId.{async, await} + def foo[T](a0: Int)(b0: Int*) = s"a0 = $a0, b0 = ${b0.head}" + val res = async { + var i = 0 + def get = async {i += 1; i} + foo[Int](await(get))(await(get) :: await(async(Nil)) : _*) + } + res mustBe "a0 = 1, b0 = 2" + } + + @Test + def awaitInNonPrimaryParamSectionWithLazy1() { + import _root_.scala.async.AsyncId.{async, await} + def foo[T](a: => Int)(b: Int) = b + val res = async { + def get = async {0} + foo[Int](???)(await(get)) } + res mustBe 0 } @Test - def awaitNotAllowedInNonPrimaryParamSection2() { - expectError("implementation restriction: await may only be used in the first parameter list.") { - """ - | import _root_.scala.async.AsyncId.{async, await} - | def foo[T](primary: Any)(i: Int) = i - | async { - | foo[Int](???)(await(0)) - | } - """.stripMargin + def awaitInNonPrimaryParamSectionWithLazy2() { + import _root_.scala.async.AsyncId.{async, await} + def foo[T](a: Int)(b: => Int) = a + val res = async { + def get = async {0} + foo[Int](await(get))(???) + } + res mustBe 0 + } + + @Test + def awaitWithLazy() { + import _root_.scala.async.AsyncId.{async, await} + def foo[T](a: Int, b: => Int) = a + val res = async { + def get = async {0} + foo[Int](await(get), ???) + } + res mustBe 0 + } + + @Test + def awaitOkInReciever() { + import scala.async.AsyncId.{async, await} + class Foo { def bar(a: Int)(b: Int) = a + b } + async { + await(async(new Foo)).bar(1)(2) } } |