Closed
Description
Compiler version
3.1.2-RC1-bin-20211027-435207d-NIGHTLY
Minimized code
import language.experimental.saferExceptions
def foo(): Int throws ArithmeticException = 1 / 0
def test(): Unit =
try
foo()
catch
case _: ArithmeticException => println("Caught")
Output
[error] The capability to throw exception ArithmeticException is missing.
[error] The capability can be provided by one of the following:
[error] - A using clause `(using CanThrow[ArithmeticException])`
[error] - A `throws` clause in a result type such as `X throws ArithmeticException`
[error] - an enclosing `try` that catches ArithmeticException
[error]
[error] The following import might fix the problem:
[error]
[error] import unsafeExceptions.canThrowAny
[error]
[error] foo()
[error] ^
Expectation
This should compile successfully.
When this gets compiled with -Xprint:typer
, one can see that the synthesized CanThrow
instance is actually
final lazy given erased val evidence$2: CanThrow[Nothing] = ???
instead of the expected CanThrow[ArithmeticException]
.
The same problems occurs e.g. for IndexOutOfBoundsException
.