Skip to content

Allow (...) around throws alternatives #13823

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

Closed
wants to merge 1 commit into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Oct 26, 2021

Fixes #13816

@odersky odersky assigned odersky and prolativ and unassigned odersky Oct 26, 2021
@odersky odersky requested a review from prolativ October 26, 2021 15:28
def foo4(i: Int)(using CanThrow[Ex1])(using CanThrow[Ex2]) =
if i > 0 then throw new Ex1 else throw new Ex2

//def foo5(i: Int)(using CanThrow[Ex1 & Ex2]) = // does not work: no capability aggregation is supported
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally in the reported issue there was (using CanThrow[Ex1 | Ex2]) instead of (using CanThrow[Ex1 & Ex2]) and we need a separate negative test to check the error message in this case because it's wrong now. It still suggests adding (using CanThrow[Ex1 | Ex2]) clause to the method almost it's already there and it's not supposed to work.
In case of (using CanThrow[Ex1 & Ex2]) we could also try to make the compiler give a better message explaining why this might be wrong

Copy link
Contributor Author

@odersky odersky Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll take a look.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have throws E1, E2 which will mirror the new extends Class1, Class2 syntax but probably off topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would lead to ambiguities.

@odersky odersky closed this Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safer exceptions with many cases in catch
3 participants