diff options
author | Tiark Rompf <tiark.rompf@epfl.ch> | 2012-03-02 23:23:56 +0100 |
---|---|---|
committer | Tiark Rompf <tiark.rompf@epfl.ch> | 2012-03-02 23:23:56 +0100 |
commit | 9f5767dd31395cac0bc64c86c2cacf247b1924fa (patch) | |
tree | 2f4b27e5f61ae9402d9b77ee2d22240caac4288d /test | |
parent | 54b541b103f79bdfff96227eeeac1d92d68165d8 (diff) | |
download | scala-9f5767dd31395cac0bc64c86c2cacf247b1924fa.tar.gz scala-9f5767dd31395cac0bc64c86c2cacf247b1924fa.tar.bz2 scala-9f5767dd31395cac0bc64c86c2cacf247b1924fa.zip |
Fix for cps regression. Closes 5538. Closes 5445.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/continuations-neg/t5445.check | 4 | ||||
-rw-r--r-- | test/files/continuations-neg/t5445.scala | 5 | ||||
-rw-r--r-- | test/files/continuations-run/t5538.check | 1 | ||||
-rw-r--r-- | test/files/continuations-run/t5538.scala | 50 |
4 files changed, 60 insertions, 0 deletions
diff --git a/test/files/continuations-neg/t5445.check b/test/files/continuations-neg/t5445.check new file mode 100644 index 0000000000..eb2943b6a6 --- /dev/null +++ b/test/files/continuations-neg/t5445.check @@ -0,0 +1,4 @@ +t5445.scala:4: error: cps annotations not allowed on by-value parameters or value definitions + def foo(block: Unit @suspendable ): Unit @suspendable = {} + ^ +one error found diff --git a/test/files/continuations-neg/t5445.scala b/test/files/continuations-neg/t5445.scala new file mode 100644 index 0000000000..cb6f8f686d --- /dev/null +++ b/test/files/continuations-neg/t5445.scala @@ -0,0 +1,5 @@ +import scala.util.continuations._ + +object Test { + def foo(block: Unit @suspendable ): Unit @suspendable = {} +} diff --git a/test/files/continuations-run/t5538.check b/test/files/continuations-run/t5538.check new file mode 100644 index 0000000000..457721d5e0 --- /dev/null +++ b/test/files/continuations-run/t5538.check @@ -0,0 +1 @@ +Future(Future(Future(Future(Future(List(1, 2, 3, 4, 5)))))) diff --git a/test/files/continuations-run/t5538.scala b/test/files/continuations-run/t5538.scala new file mode 100644 index 0000000000..42f8163caf --- /dev/null +++ b/test/files/continuations-run/t5538.scala @@ -0,0 +1,50 @@ +import scala.util.continuations._ +import scala.collection.generic.CanBuildFrom + +object Test { + + class ExecutionContext + + implicit def defaultExecutionContext = new ExecutionContext + + case class Future[+T](x:T) { + final def map[A](f: T => A): Future[A] = new Future[A](f(x)) + final def flatMap[A](f: T => Future[A]): Future[A] = f(x) + } + + class PromiseStream[A] { + override def toString = xs.toString + + var xs: List[A] = Nil + + final def +=(elem: A): this.type = { xs :+= elem; this } + + final def ++=(elem: Traversable[A]): this.type = { xs ++= elem; this } + + final def <<(elem: Future[A]): PromiseStream[A] @cps[Future[Any]] = + shift { cont: (PromiseStream[A] => Future[Any]) => elem map (a => cont(this += a)) } + + final def <<(elem1: Future[A], elem2: Future[A], elems: Future[A]*): PromiseStream[A] @cps[Future[Any]] = + shift { cont: (PromiseStream[A] => Future[Any]) => Future.flow(this << elem1 << elem2 <<< Future.sequence(elems.toSeq)) map cont } + + final def <<<(elems: Traversable[A]): PromiseStream[A] @cps[Future[Any]] = + shift { cont: (PromiseStream[A] => Future[Any]) => cont(this ++= elems) } + + final def <<<(elems: Future[Traversable[A]]): PromiseStream[A] @cps[Future[Any]] = + shift { cont: (PromiseStream[A] => Future[Any]) => elems map (as => cont(this ++= as)) } + } + + object Future { + + def sequence[A, M[_] <: Traversable[_]](in: M[Future[A]])(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]], executor: ExecutionContext): Future[M[A]] = + new Future(in.asInstanceOf[Traversable[Future[A]]].map((f:Future[A])=>f.x)(cbf.asInstanceOf[CanBuildFrom[Traversable[Future[A]], A, M[A]]])) + + def flow[A](body: => A @cps[Future[Any]])(implicit executor: ExecutionContext): Future[A] = reset(Future(body)).asInstanceOf[Future[A]] + + } + + def main(args: Array[String]) = { + val p = new PromiseStream[Int] + println(Future.flow(p << (Future(1), Future(2), Future(3), Future(4), Future(5)))) + } +}
\ No newline at end of file |