From 0c02ecf45448775913238533f60eed7c14146cdb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 7 Feb 2019 21:49:54 +0100 Subject: [PATCH] Tests to clarify projection and erased paths --- tests/neg/erased-path.scala | 10 +++++++++ tests/neg/erased-singleton.scala | 7 +++++++ tests/pos-scala2/type-projection.scala | 28 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tests/neg/erased-path.scala create mode 100644 tests/neg/erased-singleton.scala create mode 100644 tests/pos-scala2/type-projection.scala diff --git a/tests/neg/erased-path.scala b/tests/neg/erased-path.scala new file mode 100644 index 000000000000..f7fbda262e8e --- /dev/null +++ b/tests/neg/erased-path.scala @@ -0,0 +1,10 @@ + +trait Sys { type X } + +trait Obj { + erased val s: Sys + lazy val t: Sys + + type S = s.X // error: not a legal path, since nonfinal + type T = t.X // error: not a legal path, since nonfinal +} \ No newline at end of file diff --git a/tests/neg/erased-singleton.scala b/tests/neg/erased-singleton.scala new file mode 100644 index 000000000000..d1aad7093e4c --- /dev/null +++ b/tests/neg/erased-singleton.scala @@ -0,0 +1,7 @@ +trait Sys + +trait Obj { + erased val s: Sys + + type S = s.type // error: non final +} diff --git a/tests/pos-scala2/type-projection.scala b/tests/pos-scala2/type-projection.scala new file mode 100644 index 000000000000..e7d932fe83cf --- /dev/null +++ b/tests/pos-scala2/type-projection.scala @@ -0,0 +1,28 @@ +trait Txn[S <: Sys[S]] { + def system: S + + def newId(): S#Id + + def newVar[A](id: S#Id, init: A): S#Vr[A] +} + +trait Var[Tx, A] { + def apply()(implicit tx: Tx): A + + def update(x: A)(implicit tx: Tx): Unit +} + +trait Sys[S <: Sys[S]] { + type Tx <: Txn[S] + type Id + type Vr[A] <: Var[S#Tx, A] +} + +abstract class UseCase[S <: Sys[S]](id: S#Id) { + def mk(x: Int)(implicit tx: S#Tx): S#Vr[Int] = { + val vr = tx.newVar[Int](id, x) + vr + } + + def rd(vr: S#Vr[Int])(implicit tx: S#Tx): Int = vr() +}