aboutsummaryrefslogtreecommitdiff
path: root/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
commit9ef5f6817688f814a3450126aa7383b0928e80a0 (patch)
tree5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala
parent194be919664447631ba55446eb4874979c908d27 (diff)
downloaddotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala')
-rw-r--r--tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala b/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala
new file mode 100644
index 000000000..04b8f94e6
--- /dev/null
+++ b/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala
@@ -0,0 +1,44 @@
+object Sessions {
+ trait Session {
+ type Dual <: Session
+
+ def run(dp: Dual): Unit
+ }
+
+ sealed case class Stop() extends Session {
+ type Dual = Stop
+
+ def run(dp: Dual): Unit = {}
+ }
+
+ // can't write B <: Session{type Dual = BDual} due to limitations in type inference algorithm
+ // (type variables cannot occur on both sides of <:)
+ // using B#Dual instead of BDual is too imprecise, since it is disconnected from the actual argument that is passed for B
+ // would be nice if we could introduce a universal quantification over BDual that is not part of the
+ // type parameter list
+ sealed case class In[A, B <: Session, BDual <: Session](recv: A => B)(implicit dual: B <:< Session{type Dual=BDual}) extends Session {
+ type Dual = Out[A, BDual]
+
+ def run(dp: Dual): Unit = recv(dp.data) run dp.cont
+ }
+
+ sealed case class Out[A, B <: Session](data: A, cont: B) extends Session {
+ type Dual = In[A, cont.Dual, cont.Dual#Dual]
+
+ def run(dp: Dual): Unit = cont run dp.recv(data)
+ }
+
+ def addServer =
+ In{x: Int =>
+ In{y: Int => System.out.println("Thinking")
+ Out(x+y,
+ Stop())}}
+
+ def addClient =
+ Out(3,
+ Out(4, { System.out.println("Waiting")
+ In{z: Int => System.out.println(z)
+ Stop()}}))
+
+ def myRun = addServer run addClient
+}