Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrongly synthesized CanThrow for exceptions from Java stdlib #13846

Closed
prolativ opened this issue Oct 29, 2021 · 0 comments · Fixed by #13866
Closed

Wrongly synthesized CanThrow for exceptions from Java stdlib #13846

prolativ opened this issue Oct 29, 2021 · 0 comments · Fixed by #13866
Assignees
Labels
area:saferExceptions scala.language.experimental.saferExceptions itype:bug
Milestone

Comments

@prolativ
Copy link
Contributor

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.

@prolativ prolativ added itype:bug area:saferExceptions scala.language.experimental.saferExceptions labels Oct 29, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 3, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:saferExceptions scala.language.experimental.saferExceptions itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants