File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 4
4
| The capability to throw exception scalax.Fail is missing.
5
5
| The capability can be provided by one of the following:
6
6
| - A using clause `(using CanThrow[scalax.Fail])`
7
- | - A throws clause in a result type `X throws scalax.Fail`
7
+ | - A throws clause in a result type such as `X throws scalax.Fail`
8
8
| - an enclosing `try` that catches scalax.Fail
9
+ -- Error: tests/neg/safeThrowsStrawman.scala:27:15 ---------------------------------------------------------------------
10
+ 27 | println(bar) // error
11
+ | ^
12
+ | The capability to throw exception Exception is missing.
13
+ | The capability can be provided by one of the following:
14
+ | - A using clause `(using CanThrow[Exception])`
15
+ | - A throws clause in a result type such as `X throws Exception`
16
+ | - an enclosing `try` that catches Exception
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ import language.experimental.erasedTerms
2
2
import annotation .implicitNotFound
3
3
4
4
object scalax :
5
- @ implicitNotFound(" The capability to throw exception ${E} is missing.\n The capability can be provided by one of the following:\n - A using clause `(using CanThrow[${E}])`\n - A throws clause in a result type `X throws ${E}`\n - an enclosing `try` that catches ${E}" )
6
- erased class CanThrow [E <: Exception ]
5
+ @ implicitNotFound(" The capability to throw exception ${E} is missing.\n The capability can be provided by one of the following:\n - A using clause `(using CanThrow[${E}])`\n - A throws clause in a result type such as `X throws ${E}`\n - an enclosing `try` that catches ${E}" )
6
+ erased class CanThrow [- E <: Exception ]
7
7
8
- infix type throws [R , E <: Exception ] = CanThrow [E ] ?=> R
8
+ infix type throws [R , + E <: Exception ] = CanThrow [E ] ?=> R
9
9
10
10
class Fail extends Exception
11
11
@@ -16,10 +16,14 @@ import scalax._
16
16
def foo (x : Boolean ): Int =
17
17
if x then 1 else raise(Fail ()) // error
18
18
19
+ def bar : Int throws Exception =
20
+ raise(Fail ())
21
+
19
22
@ main def Test =
20
23
try
21
24
erased given CanThrow [Fail ] = ???
22
25
println(foo(true ))
23
26
println(foo(false ))
27
+ println(bar) // error
24
28
catch case ex : Fail =>
25
29
println(" failed" )
Original file line number Diff line number Diff line change 1
1
import language .experimental .erasedTerms
2
2
3
3
object scalax :
4
- erased class CanThrow [E <: Exception ]
4
+ erased class CanThrow [- E <: Exception ]
5
5
6
- infix type throws [R , E <: Exception ] = CanThrow [E ] ?=> R
6
+ infix type throws [R , + E <: Exception ] = CanThrow [E ] ?=> R
7
7
8
8
class Fail extends Exception
9
9
@@ -14,8 +14,8 @@ import scalax._
14
14
def foo (x : Boolean ): Int throws Fail =
15
15
if x then 1 else raise(Fail ())
16
16
17
- def bar (x : Boolean )(using CanThrow [Fail ]): Int =
18
- if x then 1 else raise( Fail () )
17
+ def bar (x : Boolean )(using CanThrow [Fail ]): Int = foo(x)
18
+ def baz : Int throws Exception = foo( false )
19
19
20
20
@ main def Test =
21
21
try
@@ -24,3 +24,8 @@ def bar(x: Boolean)(using CanThrow[Fail]): Int =
24
24
println(foo(false ))
25
25
catch case ex : Fail =>
26
26
println(" failed" )
27
+ try
28
+ given CanThrow [Exception ] = ???
29
+ println(baz)
30
+ catch case ex : Fail =>
31
+ println(" failed" )
You can’t perform that action at this time.
0 commit comments