-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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-75] Referencing a protocol function crashes the compiler #42697
Comments
Comment by Arthur Sabintsev (JIRA) You're not supposed to call functions directly on a protocol. A class conforms to the protocol and implements the method. I think your point was that the compiler is crashing due to this, and rather an error should be thrown, which is the case if you do something like: protocol MyProtocol {
static func MyFunc() -> String
}
let f = MyProtocol.MyFunc // error: static member 'MyFunc' cannot be used on instance of type 'MyProtocol.Protocol' |
Comment by Fabio Ritrovato (JIRA) That's exactly my point 🙂 |
Comment by Arthur Sabintsev (JIRA) Got it. Nice find! 🙂 |
We plan on making MyProtocol.someInstanceMethod work. You can already do this for classes, eg, class Foo { let f: Foo -> () -> () = Foo.f It should have the same behavior for protocols: protocol Foo { let f: Foo -> () -> () = Foo.f I plan on addressing this later. |
Comment by Jeremy Lew (JIRA) @slavapestov This has been hanging around for a while, do you know if it's on any roadmap? |
Comment by Justin Guedes (JIRA) @slavapestov Any update on this bug? 🙂 |
Comment by Greg Omelaenko (JIRA) Just wondering, how is
different from
? I understand this won't work if |
grego (JIRA User) in fact you've hit the nail on the head; the two forms are equivalent, and the compiler should be able to handle the first just as it can handle the second. The problem here is that partially-applied method references were emitted using a different code path than normal closures. I'm working on a change to convert these forms into ordinary closures in the type checker, which fixes various odd cases that were not supported (such as this one) and allows simplifying a lot of code in other parts of the compiler. I've got a WIP PR up: #28698 |
Attachment: Download
Environment
Xcode 7.1.1
Additional Detail from JIRA
md5: 85007b8954c0d9c1507fbd1a12838bdf
is duplicated by:
protocol P { func f() }; type(of: P.f)
relates to:
Issue Description:
The following code will crash the compiler
The text was updated successfully, but these errors were encountered: