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-1894] Return type of 'NSCoding.Protocol' is considered ObjC-compatible, but crashes #44503

Closed
belkadan opened this issue Jun 24, 2016 · 10 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers

Comments

@belkadan
Copy link
Contributor

Previous ID SR-1894
Radar None
Original Reporter @belkadan
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, StarterBug
Assignee gal (JIRA)
Priority Medium

md5: 7c3c3d2da857e9ccac5a0aca9b6a8702

Issue Description:

import Foundation
class Test: NSObject {
  @objc func foo() -> NSCoding.Protocol { return NSCoding.self }
}

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 returning Protocol (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.

@belkadan
Copy link
Contributor Author

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!

@swift-ci
Copy link
Collaborator

swift-ci commented Aug 5, 2016

Comment by Aleksey Gaponov (JIRA)

Created a PR

@jckarter
Copy link
Member

jckarter commented Aug 5, 2016

This is not a bug. Single `@objc` `Protocol` metatypes bridge to ObjC's `Protocol` class.

@jckarter
Copy link
Member

jckarter commented Aug 5, 2016

Or at least, considering the protocol to be @objc isn't a bug in and of itself; the crash should be fixed.

@jckarter
Copy link
Member

jckarter commented Aug 5, 2016

It shouldn't lose type information, since the Protocol object knows what protocol it represents, and `*.Protocol` types are unitary in Swift.

@belkadan
Copy link
Contributor Author

belkadan commented Aug 5, 2016

(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.

@belkadan
Copy link
Contributor Author

belkadan commented Aug 5, 2016

And as stated above, writing "Protocol" gives you the Objective-C type if you do need Objective-C compatibility.

@jckarter
Copy link
Member

jckarter commented Aug 5, 2016

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.

@belkadan
Copy link
Contributor Author

belkadan commented Aug 5, 2016

We can always add it back later; right now the easiest and safest thing to do is to ban it.

@belkadan
Copy link
Contributor Author

Aleksey's PR was merged. :-)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants