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-238] Support throwing subscripts #42860

Closed
swift-ci opened this issue Dec 15, 2015 · 3 comments
Closed

[SR-238] Support throwing subscripts #42860

swift-ci opened this issue Dec 15, 2015 · 3 comments
Assignees
Labels
compiler The Swift compiler in itself declarations Feature: declarations error handling feature A feature request or implementation improvement subscript Feature: Subscript declarations swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented throws & rethrows Feature → error handling: throws & rethrows

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-238
Radar None
Original Reporter anviking (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 24
Component/s
Labels Improvement, LanguageFeatureRequest
Assignee @theblixguy
Priority Medium

md5: d1f830bfd05395ee30fb2819cb12b391

relates to:

  • SR-115 Support generic constraints in subscripts

Issue Description:

Support for throwing subscripts would together with generic ones be really nice for JSON mapping/deserializing libraries like mine https://github.com/Anviking/Decodable. It would make subscripts an alternative to custom operators.

For example:
subscript<T: SomeProtocol>(key: String) throws -> T

Would most likely be useful on its own for a lot of other things as well.

@theblixguy
Copy link
Collaborator

There is now a WIP implementation that supports throwable getters and setters which can be used inside both computed properties and subscripts. There's still a bit of work left, but hopefully it should be finished soon: #22749

@xAlien95
Copy link
Contributor

xAlien95 commented Jul 7, 2021

Throwing subscripts are available in Swift 5.5 due to SE-0310 Effectful Read-only Properties. Should this issue be marked as resolved?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@endeavour42
Copy link

endeavour42 commented Apr 10, 2024

SE-0310 only allows throwing getter-only subscripts, setters are prohibited when getter is marked as throwing. I believe having a throwing subscript with both getter and setter would be handy:

let element = try array[at: index]
try array[at: index] = value

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself error handling subscript Feature: Subscript declarations declarations Feature: declarations throws & rethrows Feature → error handling: throws & rethrows swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself declarations Feature: declarations error handling feature A feature request or implementation improvement subscript Feature: Subscript declarations swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented throws & rethrows Feature → error handling: throws & rethrows
Projects
None yet
Development

No branches or pull requests

5 participants