Skip to content

Preserve availability on ObjC subscript getters and setters #17105

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

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

ChristopherRogers
Copy link
Contributor

Objective-C subscript accessors' attributes were being imported through the alternative declaration (getAlternateDecls(decl)) of one of the accessors (usually the getter), and this alternative declaration was the entire subscript declaration, not the getter or setter. Since there is no 1:1 equivalent between Objective-C and Swift of a subscript declaration like there is a property declaration, I opted to not import any attributes to the Swift subscript declaration we generate. The accessor attributes are imported 1:1 to their respective Swift thunks.

I noticed that, for "unavailable" subscripts, diagnostics outputs a "note" to point out where the subscript was marked unavailable but it doesn't output where. I would expect it to be able to point out the line in the Objective-C header, but it tries to point out the thunk, which is generated and thus nothing gets output. It seems there are similar problems with normal properties, except that it shows the hidden __ObjC module's generated Swift interface. Therefore I assumed that my fix didn't break those diagnostics.

I changed one dyn_cast to cast because I didn't think there would be a case where it would fail, and a couple of lines down there was a dereference anyways.

Resolves SR-7398.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

It's a little unfortunate that the error message will always call out the getter or setter even if it's the whole subscript that's supposed to logically be deprecated/unavailable, but I guess that's just an artifact of Objective-C. (Maybe we can enhance this in the future if they have the same availability and message or something.) Looks good to me; thanks for taking this, Christopher!

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@jrose-apple
Copy link
Contributor

@swift-ci Please test source compatibility

@AnnaZaks
Copy link
Contributor

@swift-ci Please test

@jrose-apple
Copy link
Contributor

Whoops, sorry for dropping this! Thanks, Anna.

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.

3 participants