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-1480] Subclasses do not inherit protocol conformance from superclasses as of Xcode 7.3.1 #44089
Comments
Comment by Bryan Irace (JIRA) Seems similar to this: https://bugs.swift.org/browse/SR-1158 |
irace (JIRA User) Do you have a project that reproduces the bug? I tried pasting the code into a new file into a fresh iOS single-view application project, and it builds successfully. I was also successfully able to compile a standalone file with `swiftc`: import UIKit
protocol Foo {
}
extension Foo {
func bar() -> Self { return self }
}
extension NSObject: Foo {}
let view = UIView().bar() // Value of type `UIView` has no member `bar` |
Comment by Bryan Irace (JIRA) Hmmm... it also is not happening for me in a fresh iOS single-view application project, but it does happen in (both of) my “real” projects. I can't share either of those though... Is there anything in particular I should be looking for, when comparing e.g. build settings between my actual projects and this dummy one that works? |
irace (JIRA User) A couple possible influencers come to mind:
|
On the off chance you have multiple Xcodes installed, or multiple Swift toolchains installed, you might double-check that you have the right Xcode |
Comment by Nick DiStefano (JIRA) irace (JIRA User) @jckarter Adding an extension on UIView brings this error to the playground for me. |
Comment by Ray Migneco (JIRA) I was able to reproduce the issue in my project using Xcode 7.3.1 The "solution" was re-ordering the source files for the compiler by editing the PBX. In this specific case, there was an extension on my subclass that I placed last in the PBX file. By doing this, I was able to compile my project without build errors. For what it's worth, I also tried module optimization and this did not fix the issue. |
rmigneco (JIRA User) Would you be able to share a project that shows the problem? |
ndis1 (JIRA User) Thanks! The |
Comment by Ray Migneco (JIRA) @jckarter I can't share my employer's project code and having some issues reproducing on a simplified scale. In essence, the issue is very similar to what ndis1 (JIRA User) shared with his playground example |
Thanks rmigneco (JIRA User). I can look into ndis1 (JIRA User)'s case, but I'm not sure your or irace (JIRA User)'s problem is exactly the same, since it involves multiple files. Let me know if you do manage to isolate it. |
Comment by Nick DiStefano (JIRA) @jckarter Attached is a version of this error in a project. If the file `DummyExtension.swift` is the first file in Compile Sources, the build will fail. If `DummyExtension.swift` is moved down so that it is after `ViewController.swift` the project will build |
ndis1 (JIRA User) Thanks! This sounds more like the situation Bryan and Ray are in. |
Playing around a bit, it appears that the single-file case only affects imported Objective-C classes. I tried a single-file pure Swift test case, and it worked: class Object {}
class Responder: Object {}
class View: Responder {}
extension View {}
protocol Foo {}
extension Foo {
func bar() -> Self { return self }
}
extension Object: Foo {}
_ = Responder().bar()
_ = View().bar() I also tried breaking Once I move the class hierarchy into a bridging header, the bug repros: // bridging.h
__attribute__((objc_root_class))
@interface Object
+alloc;
-init;
@end
@interface Responder: Object
@end
@interface View: Responder
@end // test.swift
extension View {}
protocol Foo {}
extension Foo {
func bar() -> Self { return self }
}
extension Object: Foo {}
_ = Responder().bar() // Works
_ = View().bar() // Fails ndis1 (JIRA User) rmigneco (JIRA User) irace (JIRA User) is this consistent with the problems you're seeing? Do you ever see this also happen with native Swift class hierarchies? |
Comment by Bryan Irace (JIRA) My issue is specifically with an extension on NSObject. |
Comment by Nick DiStefano (JIRA) It is consistent with what I have seen. I have not seen it with native Swift class hierarchies |
Also appears to only affect grandchild classes of the conforming type. If the dummy extension and method invocation are performed on `Responder` instead of `View`, the test works. |
Comment by Ray Migneco (JIRA) @jckarter Thanks for following up. My set-up does involve objective C:
By ensuring that the file containing the extension on Class B is compiled last, there is no compile time error. Otherwise, I receive the error. A work-around is to define a redundant extension on Class B that conforms to the protocol but this seems unnecessary in the long-term. |
rmigneco (JIRA User) Does class B directly inherit class A, or are there superclasses in between them? |
Comment by Ray Migneco (JIRA) @jckarter B directly inherits from A |
Interesting, in my test case, the bug doesn't repro for |
Comment by Ray Migneco (JIRA) Sorry, I have to update my earlier description. My class B actually is a grandchild class. Class A, which I mentioned previously, actually inherits from another class which conforms to the protocol. |
Thanks for double-checking! |
Trying out a fix: #2565 |
Fix merged as c88720e. |
Attachment: Download
Environment
Xcode Version 7.3.1 (7D1014)
Additional Detail from JIRA
md5: 327a189ed01c04fc9cc3cc6c213709b3
Issue Description:
The following code worked in Xcode 7.3 and still works in a 7.3.1 playground, but no longer works in a 7.3.1 project file:
The text was updated successfully, but these errors were encountered: