File tree Expand file tree Collapse file tree 3 files changed +74
-22
lines changed
tests/pos-custom-args/captures Expand file tree Collapse file tree 3 files changed +74
-22
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def raise[E <: Exception](ex: E)(using CanThrow[E]): Nothing =
15
15
16
16
def test1 : Int =
17
17
def f (a : Boolean ): Boolean => CanThrow [IOException ] ?=> Int =
18
- handle { // error
18
+ handle {
19
19
if ! a then raise(IOException ())
20
20
(b : Boolean ) => (_ : CanThrow [IOException ]) ?=>
21
21
if ! b then raise(IOException ())
@@ -25,27 +25,8 @@ def test1: Int =
25
25
}
26
26
handle {
27
27
val g = f(true )
28
- g(false ) // would raise an uncaught exception
29
- f(true )(false ) // would raise an uncaught exception
28
+ g(false )
29
+ f(true )(false )
30
30
} {
31
31
ex => - 1
32
32
}
33
- /*
34
- def test2: Int =
35
- def f(a: Boolean): Boolean => CanThrow[IOException] ?=> Int =
36
- handle { // error
37
- if !a then raise(IOException())
38
- (b: Boolean) =>
39
- if !b then raise(IOException())
40
- 0
41
- } {
42
- ex => (b: Boolean) => -1
43
- }
44
- handle {
45
- val g = f(true)
46
- g(false) // would raise an uncaught exception
47
- f(true)(false) // would raise an uncaught exception
48
- } {
49
- ex => -1
50
- }
51
- */
Original file line number Diff line number Diff line change
1
+ import language .experimental .erasedDefinitions
2
+ import annotation .ability
3
+ import java .io .IOException
4
+
5
+ class CanThrow [E ] extends Retains [* ]
6
+ type Top = Any retains *
7
+ infix type ==> [A , B ] = (A => B ) retains *
8
+ class OtherCap extends Retains [* ]
9
+
10
+ def handle [E <: Exception , T <: Top ](op : (CanThrow [E ] ?=> T ))(handler : (E => T ) retains T ): T =
11
+ val x : CanThrow [E ] = ???
12
+ try op(using x)
13
+ catch case ex : E => handler(ex)
14
+
15
+ def raise [E <: Exception ](ex : E )(using CanThrow [E ]): Nothing =
16
+ throw ex
17
+
18
+ def test2 : Int =
19
+ def f (c : OtherCap , a : Boolean ): Boolean => CanThrow [IOException ] ?=> Int =
20
+ handle {
21
+ if ! a then raise(IOException ())
22
+ (b : Boolean ) => (_ : CanThrow [IOException ]) ?=>
23
+ if ! b then raise(IOException ())
24
+ 1
25
+ } {
26
+ ex => (b : Boolean ) => (_ : CanThrow [IOException ]) ?=> - 1
27
+ }
28
+ handle {
29
+ val c = OtherCap ()
30
+ val g = f(c, true )
31
+ g(false )
32
+ f(c, true )(false )
33
+ } {
34
+ ex => - 1
35
+ }
Original file line number Diff line number Diff line change
1
+ import language.experimental.erasedDefinitions
2
+ import annotation.ability
3
+ import java.io.IOException
4
+
5
+ class CanThrow[E] extends Retains[*]
6
+ type Top = Any retains *
7
+ infix type ==> [A, B] = (A => B) retains *
8
+ class OtherCap extends Retains[*]
9
+
10
+ def handle[E <: Exception, T <: Top](op: (CanThrow[E] ?=> T) retains T)(handler: (E => T) retains T): T =
11
+ val x: CanThrow[E] = ???
12
+ try op(using x)
13
+ catch case ex: E => handler(ex)
14
+
15
+ def raise[E <: Exception](ex: E)(using CanThrow[E]): Nothing =
16
+ throw ex
17
+
18
+ def test2: Unit =
19
+ def f(c: OtherCap, a: Boolean): (Boolean => (CanThrow[IOException] ?=> (Int => Int) retains c.type) retains c.type) retains c.type =
20
+ handle {
21
+ if !a then raise(IOException())
22
+ (b: Boolean) => (_: CanThrow[IOException]) ?=>
23
+ if !b then raise(IOException())
24
+ (x: Int) => { 1 }
25
+ } {
26
+ ex => (b: Boolean) => (_: CanThrow[IOException]) ?=> (x: Int) => { c; -1 }
27
+ }
28
+ val c = OtherCap()
29
+ handle[IOException, (Int => Int) retains c.type] {
30
+ val g = f(c, true)
31
+ g(false)
32
+ f(c, true)(false)
33
+ } {
34
+ ex => (x: Int) => { c; -1 }
35
+ }
36
+ ()
You can’t perform that action at this time.
0 commit comments