-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CanThrow capability shouldn't be synthesized for nonexhaustive catch clauses #13849
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
Comments
We should also think how/whether to handle situations when a match is exhaustive but spread across multiple try/catch clauses, e.g. import annotation.experimental
import language.experimental.saferExceptions
@experimental
case class Ex(i: Int) extends Exception(s"Exception: $i")
@experimental
def foo(): Unit throws Ex = Ex(1)
@experimental
object Main:
def main(args: Array[String]): Unit =
try
try
foo()
catch
case Ex(x) if x > 0 => println("Caught positive Ex")
catch
case Ex(x) if x <= 0 => println("Caught nonpositive Ex") |
I don't think there's a chance we could handle this. |
The intention is that this is a simple & transparent desugaring. That means we should not overthink this and add all sorts of additional conditions for certain things to trigger. |
How about synthesizing |
Yes I think that is the way to go. I think we should make it an error to use other handlers for checked exceptions if saferExceptions is imported. |
Restrict catch patterns to `ex: T` with no guard under saferExceptions so that capabilities can be generated safely. Fixes scala#13849
Restrict catch patterns to `ex: T` with no guard under saferExceptions so that capabilities can be generated safely. Fixes scala#13849
Compiler version
3.1.1-RC1
Minimized code
Output
Expectation
This should not compile. The compiler should not synthesize given instances of
CanThrow
if it cannot prove at compile time that all subcases for a given exception type are handled.Beside boolean guards we should also handle extractors like
The text was updated successfully, but these errors were encountered: