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 44 | The capability to throw exception scalax.Fail is missing.
55 | The capability can be provided by one of the following:
66 | - 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`
88 | - 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
22import annotation .implicitNotFound
33
44object 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 ]
77
8- infix type throws [R , E <: Exception ] = CanThrow [E ] ?=> R
8+ infix type throws [R , + E <: Exception ] = CanThrow [E ] ?=> R
99
1010 class Fail extends Exception
1111
@@ -16,10 +16,14 @@ import scalax._
1616def foo (x : Boolean ): Int =
1717 if x then 1 else raise(Fail ()) // error
1818
19+ def bar : Int throws Exception =
20+ raise(Fail ())
21+
1922@ main def Test =
2023 try
2124 erased given CanThrow [Fail ] = ???
2225 println(foo(true ))
2326 println(foo(false ))
27+ println(bar) // error
2428 catch case ex : Fail =>
2529 println(" failed" )
Original file line number Diff line number Diff line change 11import language .experimental .erasedTerms
22
33object scalax :
4- erased class CanThrow [E <: Exception ]
4+ erased class CanThrow [- E <: Exception ]
55
6- infix type throws [R , E <: Exception ] = CanThrow [E ] ?=> R
6+ infix type throws [R , + E <: Exception ] = CanThrow [E ] ?=> R
77
88 class Fail extends Exception
99
@@ -14,8 +14,8 @@ import scalax._
1414def foo (x : Boolean ): Int throws Fail =
1515 if x then 1 else raise(Fail ())
1616
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 )
1919
2020@ main def Test =
2121 try
@@ -24,3 +24,8 @@ def bar(x: Boolean)(using CanThrow[Fail]): Int =
2424 println(foo(false ))
2525 catch case ex : Fail =>
2626 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