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-115] Support generic constraints in subscripts #42737

Closed
swift-ci opened this issue Dec 7, 2015 · 12 comments
Closed

[SR-115] Support generic constraints in subscripts #42737

swift-ci opened this issue Dec 7, 2015 · 12 comments
Assignees
Labels
compiler The Swift compiler itself feature A feature request or implementation improvement

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2015

Previous ID SR-115
Radar rdar://problem/21461357
Original Reporter radex (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 11
Component/s Compiler
Labels Improvement, LanguageFeatureRequest
Assignee @slavapestov
Priority Medium

md5: ea5cb771b99703784bb1dd3c9e7cf4ed

blocks:

  • SR-3460 Replace _AnyHashable protocol with a generic subscript

relates to:

  • SR-238 Support throwing subscripts

Issue Description:

It would really help me and my library (https://github.com/radex/swiftyuserdefaults) to be able to use generic constraints on subscripts, e.g.

subscript<T: SomeProtocol>(key: DefaultsKey<T>) -> T { ... }

@lattner already indicated on the mailing list that this is considered a current language limitation, not a design choice, so I thought it might be useful to have a JIRA issue for tracking progress on this.

@stephencelis
Copy link
Contributor

If anyone is curious or wants to help, I've started a naïve branch here: https://github.com/stephencelis/swift/tree/generic-subscripts

I've gotten the parser to stop complaining and am working on getting the resolver to play nicely with subscript access.

Once I have things working, I'll submit a pull request and elicit feedback from people with more compiler experience.

@swift-ci
Copy link
Contributor Author

Comment by Johannes Lund (JIRA)

Don't know if this should be its own issue, but if the generic subscripts also could be throwing it would be really interesting for all of the Swift JSON deserializers/mappers, including mine https://github.com/Anviking/Decodable

@swift-ci
Copy link
Contributor Author

Comment by Radek Pietruszewski (JIRA)

@johannes Related, but deserves its own issue, IMO

@stephencelis
Copy link
Contributor

anviking (JIRA User) Yep. Feel free to post another issue and/or start a swift-evolution thread around possible syntax, etc.

@benrimmington
Copy link
Contributor

@benrimmington
Copy link
Contributor

@@slavapestov: Does your implementation support default arguments for subscript parameters?

@slavapestov
Copy link
Contributor

Not yet, but I'm waiting for some SILGen work to settle down before looking at that. There's a separate SR tracking default arguments for subscripts, IIRC.

@benrimmington
Copy link
Contributor

I could only find SR-4104.

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 5, 2017

Comment by Roberto Neira (JIRA)

Is there a way to tell in which release of Swift this improvement is included?

@benrimmington
Copy link
Contributor

@neirar (JIRA User): Swift 4.0

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 7, 2017

Comment by Roberto Neira (JIRA)

@benrimmington Thanks for the quick reply.

Is there a way to see which release a fix or improvement will be included in, or a list that shows the fixes/improvements planned for a certain release?

@ole
Copy link
Contributor

ole commented Apr 7, 2017

neirar (JIRA User) The changelog at https://github.com/apple/swift/blob/master/CHANGELOG.md gives a pretty good overview of the high-level changes in each release (including the upcoming release). It also includes this one (search for "Subscript declarations can now be defined to have generic parameter lists"). It doesn't mention every single bugfix, of course.

@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
compiler The Swift compiler itself feature A feature request or implementation improvement
Projects
None yet
Development

No branches or pull requests

5 participants