Skip to content

Commit 0eaef1b

Browse files
committed
Add sealed refs test
1 parent e1f7561 commit 0eaef1b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Ref[sealed A](init: A):
2+
this: Ref[A]^ =>
3+
private var x: A = init
4+
def get: A = x
5+
def set(x: A): Unit = this.x = x
6+
7+
class It[X]:
8+
this: It[X]^ =>
9+
10+
def f1[B1](x: B1, next: B1 -> B1) =
11+
var r = x // ok
12+
r = next(x)
13+
r
14+
15+
def f2[B2](x: B2, next: B2 -> B2) =
16+
val r = Ref[B2](x) // error
17+
r.set(next(x))
18+
r.get
19+
20+
def g[sealed B](x: B, next: B -> B) =
21+
val r = Ref[B](x) // ok
22+
r.set(next(x))
23+
r.get
24+
25+
import annotation.unchecked.uncheckedCaptures
26+
27+
def h[B](x: B, next: B -> B) =
28+
val r = Ref[B @uncheckedCaptures](x) // ok
29+
r.set(next(x))
30+
r.get
31+
32+
def f3[B](x: B, next: B -> B) =
33+
val r: Ref[B^{cap[f3]}] = Ref[B^{cap[f3]}](x) // error
34+
r.set(next(x))
35+
val y = r.get
36+
()
37+
38+
def f4[B](x: B, next: B -> B) =
39+
val r: Ref[B]^{cap[f4]} = Ref[B](x) // error
40+
r.set(next(x))
41+
val y = r.get
42+
()

0 commit comments

Comments
 (0)