-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Don't inherit convenience inits if a designated init is missing. #8708
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
Don't inherit convenience inits if a designated init is missing. #8708
Conversation
@swift-ci Please test |
47a4909
to
2a72eb3
Compare
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please smoke test Linux |
@swift-ci please smoke test linux platform |
Review ping, since I think this one could definitely use a second pair of eyes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment aside, LGTM!
include/swift/AST/Decl.h
Outdated
/// This can occur, for example, if the class is an Objective-C class with | ||
/// initializers that cannot be represented in Swift. | ||
bool hasMissingDesignatedInitializers() const { | ||
(void)getMembers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we lookupDirect
on the name init
instead, so we only deserialize initializers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean when we actually do that? Yeah, good point.
@@ -107,6 +107,7 @@ __weak id globalWeakVar; | |||
- (id)getObjectFromVarArgs:(id)first, ...; | |||
@end | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious whitespace addition.
2a72eb3
to
f206384
Compare
@swift-ci Please smoke test |
f206384
to
d255f9f
Compare
@swift-ci Please smoke test |
(which can happen if an imported class has un-importable initializers) Our initializer model guarantees that it's safe to inherit convenience initializers when a subclass has implemented all designated initializers, since each convenience initializer will be implemented by calling one of the designated initializers. If one of the designated initializers /can't/ be implemented in Swift, however, then inheriting the convenience initializer would not be safe. This is potentially a source-breaking change, so the importer will only actually record that it failed to import something in when compiling in Swift 4 mode. rdar://problem/31563662
d255f9f
to
c1b4c94
Compare
@swift-ci Please smoke test |
(which can happen if an imported class has un-importable initializers)
Our initializer model guarantees that it's safe to inherit convenience initializers when a subclass has implemented all designated initializers, since each convenience initializer will be implemented by calling one of the designated initializers. If one of the designated initializers can't be implemented in Swift, however, then inheriting the convenience initializer would not be safe.
This is potentially a source-breaking change, so the importer will only actually record that it failed to import something in when compiling in Swift 4 mode. I also found an unrelated bug about initializer inheritance, which I filed as SR-4566.
I'm using this as groundwork for the "deserialization recovery" I've been doing. I'd like to do something better than dropping a designated initializer just because the declaration it overrides has changed, but this is a safe default, at least.
rdar://problem/31563662