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

[SR-8253] Catch clause should allow multiple patterns #50785

Closed
sharplet opened this issue Jul 13, 2018 · 8 comments
Closed

[SR-8253] Catch clause should allow multiple patterns #50785

sharplet opened this issue Jul 13, 2018 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@sharplet
Copy link

Previous ID SR-8253
Radar rdar://problem/42178811
Original Reporter @sharplet
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 4.2, Xcode Version 10.0 beta 3 (10L201y)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: b4c86fd321a914b3b953049c7ef2f1c9

Issue Description:

I was surprised to find that the catch clause doesn't accept the same patterns that cases in a switch do. This fails to compile:

struct Safe<T: Decodable>: Decodable {
  let decoded: T?

  init(from decoder: Decoder) throws {
    do {
      decoded = try decoder.singleValueContainer().decode(T.self)
    } catch DecodingError.dataCorrupted, DecodingError.typeMismatch, DecodingError.valueNotFound {
      decoded = nil
    }
  }
}

I've attached a playground that reproduces the issue.

@jckarter
Copy link
Member

@swift-ci create

@jckarter
Copy link
Member

Series of catch blocks are already mostly treated analogously to case labels in a switch, so hopefully this is a matter of extending the parser to accept comma-delimited lists of patterns and form the appropriate `CaseLabel` AST in response.

@rjmccall
Copy link
Member

This does seem like it ought to be a simple addition. It needs Evolution sign-off, but I'd expect that to be as close to a rubber-stamp as language proposals ever get.

@sharplet
Copy link
Author

Thanks for weighing in! Unless somebody else gets to it first, I can look into starting a pitch thread later this week.

@sharplet
Copy link
Author

@sharplet
Copy link
Author

Owen Voorhees has authored a proposal for this that’s now in review: https://github.com/apple/swift-evolution/blob/master/proposals/0276-multi-pattern-catch-clauses.md

@swift-ci
Copy link
Collaborator

Comment by Jason R Tibbetts (JIRA)

The proposal was accepted and this was released in version 5.3. Can this ticket be closed?

@sharplet
Copy link
Author

Looks good to me, marking as resolved!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants