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-1894] Return type of 'NSCoding.Protocol' is considered ObjC-compatible, but crashes #44503
Comments
Since this bug has a 100%-clear fix and yet doesn't come up very often, let's leave it for a first-time committer to get their bearings! |
Comment by Aleksey Gaponov (JIRA) Created a PR |
This is not a bug. Single `@objc` `Protocol` metatypes bridge to ObjC's `Protocol` class. |
Or at least, considering the protocol to be @objc isn't a bug in and of itself; the crash should be fixed. |
It shouldn't lose type information, since the Protocol object knows what protocol it represents, and `*.Protocol` types are unitary in Swift. |
(deleted comment) Yes, but we don't actually implement that, and it loses type information anyway. (We do allow it for classes, though, so we could reconsider.) (new response) PrintAsObjC has no way to repesent it. |
And as stated above, writing "Protocol" gives you the Objective-C type if you do need Objective-C compatibility. |
I suppose it's of marginal utility; however, as you noted, we do allow this for class metatypes despite there being no way to represent a specific `Class` in ObjC. |
We can always add it back later; right now the easiest and safest thing to do is to ban it. |
Aleksey's PR was merged. :-) |
Additional Detail from JIRA
md5: 7c3c3d2da857e9ccac5a0aca9b6a8702
Issue Description:
Compiling this with Swift 3 (preview 1) leads to a crash in SILGen trying to emit an ObjC thunk for
foo
. We should probably just not consider this to be Objective-C-compatible; it doesn't buy us much over just returningProtocol
(which works fine, though despite the name it's limited to Objective-C protocols).Banning this means altering the logic in lib/AST/Type.cpp. There's actually an explicit check marked "@objc protocol metatypes"; that entire block can be removed to make the whole function return false.
The text was updated successfully, but these errors were encountered: