Skip to content

[Typechecker] Allow @objc functions to return dynamic self #22006

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 3 commits into from
Jan 23, 2019
Merged

[Typechecker] Allow @objc functions to return dynamic self #22006

merged 3 commits into from
Jan 23, 2019

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Jan 20, 2019

This PR lifts a restriction on @objc functions which disallowed dynamic self as return type.

@objc protocol Foo {
    static func makeFoo() -> Self // ok
}

Resolves SR-7601.

@theblixguy
Copy link
Collaborator Author

theblixguy commented Jan 20, 2019

cc @jrose-apple

I am not sure if I should add a protocol restriction as well or just freely allow dynamic self as return type.

@jrose-apple
Copy link
Contributor

This seems correct to me, but it's worth adding a PrintAsObjC test too to make sure it gets printed as instancetype. @slavapestov, any additional comments?

@slavapestov
Copy link
Contributor

This change makes sense to me since we already import instancetype as Self. I would want to make sure PrintAsObjC can handle this first though.

@theblixguy
Copy link
Collaborator Author

@jrose-apple @slavapestov I have added a test file, does it look good to you?

@jrose-apple
Copy link
Contributor

Great, looks like everything works. :-)

@swift-ci Please test

@jrose-apple jrose-apple self-assigned this Jan 23, 2019
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e65014e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e65014e

@theblixguy
Copy link
Collaborator Author

theblixguy commented Jan 23, 2019

Whoops, there's a crash when running the new test file: If you're seeing a crash here, check that your SDK and dependencies are at least as new as the versions used to build 'dynamicself'

@jrose-apple do you know what could be the issue here?

@jrose-apple
Copy link
Contributor

Ah, sorry. %clang-importer-sdk doesn't work with anything past SILGen; you'll have to copy over the "-enable-source-import hackaround" lines from one of the other PrintAsObjC tests. Or just move this into existing tests (the most boring ones being classes.swift and protocols.swift).

Sorry for not catching that in the review.

@theblixguy
Copy link
Collaborator Author

@jrose-apple oh, it's alright! I have updated the test file. Can you take a look and invoke the CI again if it looks good to you?

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 34c46d9

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 34c46d9

@theblixguy
Copy link
Collaborator Author

All tests have passed 🎉 @jrose-apple

@jrose-apple jrose-apple merged commit aee0b4e into swiftlang:master Jan 23, 2019
@jrose-apple
Copy link
Contributor

Thank you for the implementation!

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.

4 participants