Skip to content

Commit 0c02ecf

Browse files
committed
Tests to clarify projection and erased paths
1 parent 732f7e2 commit 0c02ecf

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tests/neg/erased-path.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
trait Sys { type X }
3+
4+
trait Obj {
5+
erased val s: Sys
6+
lazy val t: Sys
7+
8+
type S = s.X // error: not a legal path, since nonfinal
9+
type T = t.X // error: not a legal path, since nonfinal
10+
}

tests/neg/erased-singleton.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait Sys
2+
3+
trait Obj {
4+
erased val s: Sys
5+
6+
type S = s.type // error: non final
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Txn[S <: Sys[S]] {
2+
def system: S
3+
4+
def newId(): S#Id
5+
6+
def newVar[A](id: S#Id, init: A): S#Vr[A]
7+
}
8+
9+
trait Var[Tx, A] {
10+
def apply()(implicit tx: Tx): A
11+
12+
def update(x: A)(implicit tx: Tx): Unit
13+
}
14+
15+
trait Sys[S <: Sys[S]] {
16+
type Tx <: Txn[S]
17+
type Id
18+
type Vr[A] <: Var[S#Tx, A]
19+
}
20+
21+
abstract class UseCase[S <: Sys[S]](id: S#Id) {
22+
def mk(x: Int)(implicit tx: S#Tx): S#Vr[Int] = {
23+
val vr = tx.newVar[Int](id, x)
24+
vr
25+
}
26+
27+
def rd(vr: S#Vr[Int])(implicit tx: S#Tx): Int = vr()
28+
}

0 commit comments

Comments
 (0)