-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refine handling of CanThrow capabilities #13866
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
Conversation
Restrict catch patterns to `ex: T` with no guard under saferExceptions so that capabilities can be generated safely. Fixes scala#13849
checkedArgs = checkedArgs.mapconserve(arg => | ||
checkSimpleKinded(checkNoWildcard(arg))) | ||
else if tycon == defn.throwsAlias | ||
&& checkedArgs.length == 2 | ||
&& checkedArgs(1).tpe.derivesFrom(defn.RuntimeExceptionClass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there really a gain in explicitly preventing users from declaring throwing RuntimeException
s? And even if we disallow methods like
def foo(): Int throws ArithmeticException = ???
then
def foo()(using CanThrow[ArithmeticException]): Int = ???
will be still valid, right? So this somehow defeats the purpose IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't generate a capability for it, so it's better to communicate that early. But I think ding this for throws clauses is enough. I don't want to start imposing restrictions on general implicit parameters.
| ^ | ||
| The capability to throw exception ArithmeticException is missing. | ||
| The capability can be provided by one of the following: | ||
| - A using clause `(using CanThrow[ArithmeticException])` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't synthesize instances of CanThrow
for subtypes of RuntimeException
then this message is rather misleading than helpful, as propagating this capability with using clauses won't make the compilation succeed unless someone creates such an instance by themself. And X throws ArithmeticException
won't even compile
That's an @implicitiNotFound error message, and IMO it should stay one. There is no way we can customize the message according to what the caught exception is. |
Then at least maybe we could extend the generic |
Fixes #13864
Fixes #13846
Fixes #13849