diff options
author | Philipp Haller <hallerp@gmail.com> | 2010-07-12 09:27:59 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2010-07-12 09:27:59 +0000 |
commit | 87b48f8686b627b69a180882e70acbb82a9cf5f6 (patch) | |
tree | 0a2982e1890a345d68fe0d214acc670471354135 /test/pending | |
parent | e036e2da98cd6160b7206df7fcf399aaf79d01e0 (diff) | |
download | scala-87b48f8686b627b69a180882e70acbb82a9cf5f6.tar.gz scala-87b48f8686b627b69a180882e70acbb82a9cf5f6.tar.bz2 scala-87b48f8686b627b69a180882e70acbb82a9cf5f6.zip |
Added test case for see #3620.
Diffstat (limited to 'test/pending')
-rw-r--r-- | test/pending/continuations-pos/t3620.scala | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/pending/continuations-pos/t3620.scala b/test/pending/continuations-pos/t3620.scala new file mode 100644 index 0000000000..8496ae2858 --- /dev/null +++ b/test/pending/continuations-pos/t3620.scala @@ -0,0 +1,73 @@ +import scala.collection.mutable.HashMap +import scala.util.continuations._ + +object Test extends Application { + + class Store[K,V] { + + trait Waiting { + def key: K + def inform(value: V): Unit + } + + private val map = new HashMap[K, V] + private var waiting: List[Waiting] = Nil + + def waitFor(k: K, f: (V => Unit)) { + map.get(k) match { + case Some(v) => f(v) + case None => { + val w = new Waiting { + def key = k + def inform(v: V) = f(v) + } + waiting = w :: waiting + } + } + } + + + def add(key: K, value: V) { + map(key) = value + val p = waiting.partition(_.key == key) + waiting = p._2 + p._1.foreach(_.inform(value)) + } + + def required(key: K) = { + shift { + c: (V => Unit) => { + waitFor(key, c) + } + } + } + + def option(key: Option[K]) = { + shift { + c: (Option[V] => Unit) => { + key match { + case Some(key) => waitFor(key, (v: V) => c(Some(v))) + case None => c(None) + } + + } + } + } + + } + + val store = new Store[String, Int] + + def test(p: Option[String]): Unit = { + reset { + // uncommenting the following two lines makes the compiler happy! +// val o = store.option(p) +// println(o) + val i = store.option(p).getOrElse(1) + println(i) + } + } + + test(Some("a")) + +} |