Skip to content

[ClangImporter] Follow-up for #32214, fix assertion hit due to missing check #32401

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7401,7 +7401,9 @@ void SwiftDeclConverter::importInheritedConstructors(

Impl.importAttributes(objcMethod, newCtor, curObjCClass);
newMembers.push_back(newCtor);
} else if (existing && existing->getClangDecl()) {
} else if (existing && existing->getInitKind() ==
CtorInitializerKind::ConvenienceFactory &&
existing->getClangDecl()) {
// Check that the existing constructor the prevented new creation is
// really an inherited factory initializer and not a class member.
auto existingMD = cast<clang::ObjCMethodDecl>(existing->getClangDecl());
Expand Down
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/Foo-new-version/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
@interface PhotoSettings: NSObject
+ (instancetype)photoSettingsWithFormat:(int)format;
+ (instancetype)photoSettingsWithNumber:(int)number;

+ (instancetype)photoSettingsWithCake:(int)cake;
- (instancetype)initWithCake:(int)cake;
@end

@interface PhotoBracketSettings : PhotoSettings
Expand Down
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/Foo/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
@interface PhotoSettings: NSObject
+ (instancetype)photoSettingsWithFormat:(int)format;
+ (instancetype)photoSettingsWithNumber:(int)number;

+ (instancetype)photoSettingsWithCake:(int)cake;
- (instancetype)initWithCake:(int)cake;
@end

@interface PhotoBracketSettings : PhotoSettings
Expand Down
75 changes: 75 additions & 0 deletions test/api-digester/Outputs/clang-module-dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,45 @@
],
"init_kind": "ConvenienceFactory"
},
{
"kind": "Constructor",
"name": "init",
"printedName": "init(cake:)",
"children": [
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "Foo.PhotoBracketSettings?",
"children": [
{
"kind": "TypeNominal",
"name": "PhotoBracketSettings",
"printedName": "Foo.PhotoBracketSettings",
"usr": "c:objc(cs)PhotoBracketSettings"
}
],
"usr": "s:Sq"
},
{
"kind": "TypeNominal",
"name": "Int32",
"printedName": "Swift.Int32",
"usr": "s:s5Int32V"
}
],
"declKind": "Constructor",
"usr": "c:objc(cs)PhotoSettings(im)initWithCake:",
"moduleName": "Foo",
"overriding": true,
"implicit": true,
"objc_name": "initWithCake:",
"declAttributes": [
"Override",
"ObjC",
"Dynamic"
],
"init_kind": "Designated"
},
{
"kind": "Constructor",
"name": "init",
Expand Down Expand Up @@ -469,6 +508,42 @@
],
"init_kind": "ConvenienceFactory"
},
{
"kind": "Constructor",
"name": "init",
"printedName": "init(cake:)",
"children": [
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "Foo.PhotoSettings?",
"children": [
{
"kind": "TypeNominal",
"name": "PhotoSettings",
"printedName": "Foo.PhotoSettings",
"usr": "c:objc(cs)PhotoSettings"
}
],
"usr": "s:Sq"
},
{
"kind": "TypeNominal",
"name": "Int32",
"printedName": "Swift.Int32",
"usr": "s:s5Int32V"
}
],
"declKind": "Constructor",
"usr": "c:objc(cs)PhotoSettings(im)initWithCake:",
"moduleName": "Foo",
"objc_name": "initWithCake:",
"declAttributes": [
"ObjC",
"Dynamic"
],
"init_kind": "Designated"
},
{
"kind": "Constructor",
"name": "init",
Expand Down