Skip to content

Commit f89a385

Browse files
committed
[ClangImporter] Follow-up for #32214, fix assertion hit due to missing check
1 parent 80e2b48 commit f89a385

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7401,7 +7401,9 @@ void SwiftDeclConverter::importInheritedConstructors(
74017401

74027402
Impl.importAttributes(objcMethod, newCtor, curObjCClass);
74037403
newMembers.push_back(newCtor);
7404-
} else if (existing && existing->getClangDecl()) {
7404+
} else if (existing && existing->getInitKind() ==
7405+
CtorInitializerKind::ConvenienceFactory &&
7406+
existing->getClangDecl()) {
74057407
// Check that the existing constructor the prevented new creation is
74067408
// really an inherited factory initializer and not a class member.
74077409
auto existingMD = cast<clang::ObjCMethodDecl>(existing->getClangDecl());

test/api-digester/Inputs/Foo-new-version/foo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
@interface PhotoSettings: NSObject
2222
+ (instancetype)photoSettingsWithFormat:(int)format;
2323
+ (instancetype)photoSettingsWithNumber:(int)number;
24+
25+
+ (instancetype)photoSettingsWithCake:(int)cake;
26+
- (instancetype)initWithCake:(int)cake;
2427
@end
2528

2629
@interface PhotoBracketSettings : PhotoSettings

test/api-digester/Inputs/Foo/foo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
@interface PhotoSettings: NSObject
1616
+ (instancetype)photoSettingsWithFormat:(int)format;
1717
+ (instancetype)photoSettingsWithNumber:(int)number;
18+
19+
+ (instancetype)photoSettingsWithCake:(int)cake;
20+
- (instancetype)initWithCake:(int)cake;
1821
@end
1922

2023
@interface PhotoBracketSettings : PhotoSettings

test/api-digester/Outputs/clang-module-dump.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,45 @@
324324
],
325325
"init_kind": "ConvenienceFactory"
326326
},
327+
{
328+
"kind": "Constructor",
329+
"name": "init",
330+
"printedName": "init(cake:)",
331+
"children": [
332+
{
333+
"kind": "TypeNominal",
334+
"name": "Optional",
335+
"printedName": "Foo.PhotoBracketSettings?",
336+
"children": [
337+
{
338+
"kind": "TypeNominal",
339+
"name": "PhotoBracketSettings",
340+
"printedName": "Foo.PhotoBracketSettings",
341+
"usr": "c:objc(cs)PhotoBracketSettings"
342+
}
343+
],
344+
"usr": "s:Sq"
345+
},
346+
{
347+
"kind": "TypeNominal",
348+
"name": "Int32",
349+
"printedName": "Swift.Int32",
350+
"usr": "s:s5Int32V"
351+
}
352+
],
353+
"declKind": "Constructor",
354+
"usr": "c:objc(cs)PhotoSettings(im)initWithCake:",
355+
"moduleName": "Foo",
356+
"overriding": true,
357+
"implicit": true,
358+
"objc_name": "initWithCake:",
359+
"declAttributes": [
360+
"Override",
361+
"ObjC",
362+
"Dynamic"
363+
],
364+
"init_kind": "Designated"
365+
},
327366
{
328367
"kind": "Constructor",
329368
"name": "init",
@@ -469,6 +508,42 @@
469508
],
470509
"init_kind": "ConvenienceFactory"
471510
},
511+
{
512+
"kind": "Constructor",
513+
"name": "init",
514+
"printedName": "init(cake:)",
515+
"children": [
516+
{
517+
"kind": "TypeNominal",
518+
"name": "Optional",
519+
"printedName": "Foo.PhotoSettings?",
520+
"children": [
521+
{
522+
"kind": "TypeNominal",
523+
"name": "PhotoSettings",
524+
"printedName": "Foo.PhotoSettings",
525+
"usr": "c:objc(cs)PhotoSettings"
526+
}
527+
],
528+
"usr": "s:Sq"
529+
},
530+
{
531+
"kind": "TypeNominal",
532+
"name": "Int32",
533+
"printedName": "Swift.Int32",
534+
"usr": "s:s5Int32V"
535+
}
536+
],
537+
"declKind": "Constructor",
538+
"usr": "c:objc(cs)PhotoSettings(im)initWithCake:",
539+
"moduleName": "Foo",
540+
"objc_name": "initWithCake:",
541+
"declAttributes": [
542+
"ObjC",
543+
"Dynamic"
544+
],
545+
"init_kind": "Designated"
546+
},
472547
{
473548
"kind": "Constructor",
474549
"name": "init",

0 commit comments

Comments
 (0)