@@ -4313,12 +4313,12 @@ namespace {
4313
4313
// "raw" name will be imported as unavailable with a more helpful and
4314
4314
// specific message.
4315
4315
++NumFactoryMethodsAsInitializers;
4316
- bool redundant = false ;
4316
+ ConstructorDecl *existing = nullptr ;
4317
4317
auto result =
4318
4318
importConstructor (decl, dc, false , importedName.getInitKind (),
4319
4319
/* required=*/ false , selector, importedName,
4320
4320
{decl->param_begin (), decl->param_size ()},
4321
- decl->isVariadic (), redundant );
4321
+ decl->isVariadic (), existing );
4322
4322
4323
4323
if (!isActiveSwiftVersion () && result)
4324
4324
markAsVariant (result, *correctSwiftName);
@@ -4562,7 +4562,7 @@ namespace {
4562
4562
ImportedName importedName,
4563
4563
ArrayRef<const clang::ParmVarDecl*> args,
4564
4564
bool variadic,
4565
- bool &redundant );
4565
+ ConstructorDecl *&existing );
4566
4566
4567
4567
void recordObjCOverride (SubscriptDecl *subscript);
4568
4568
@@ -6241,11 +6241,11 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6241
6241
variadic = false ;
6242
6242
}
6243
6243
6244
- bool redundant ;
6244
+ ConstructorDecl *existing ;
6245
6245
auto result = importConstructor (objcMethod, dc, implicit,
6246
6246
kind.getValueOr (importedName.getInitKind ()),
6247
6247
required, selector, importedName, params,
6248
- variadic, redundant );
6248
+ variadic, existing );
6249
6249
6250
6250
// If this is a compatibility stub, mark it as such.
6251
6251
if (result && correctSwiftName)
@@ -6357,8 +6357,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6357
6357
const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
6358
6358
CtorInitializerKind kind, bool required, ObjCSelector selector,
6359
6359
ImportedName importedName, ArrayRef<const clang::ParmVarDecl *> args,
6360
- bool variadic, bool &redundant ) {
6361
- redundant = false ;
6360
+ bool variadic, ConstructorDecl *&existing ) {
6361
+ existing = nullptr ;
6362
6362
6363
6363
// Figure out the type of the container.
6364
6364
auto ownerNominal = dc->getSelfNominalTypeDecl ();
@@ -6458,7 +6458,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6458
6458
6459
6459
// Otherwise, we shouldn't create a new constructor, because
6460
6460
// it will be no better than the existing one.
6461
- redundant = true ;
6461
+ existing = ctor ;
6462
6462
return nullptr ;
6463
6463
}
6464
6464
@@ -7395,19 +7395,26 @@ void SwiftDeclConverter::importInheritedConstructors(
7395
7395
!correctSwiftName &&
7396
7396
" Import inherited initializers never references correctSwiftName" );
7397
7397
importedName.setHasCustomName ();
7398
- bool redundant ;
7398
+ ConstructorDecl *existing ;
7399
7399
if (auto newCtor =
7400
7400
importConstructor (objcMethod, classDecl,
7401
7401
/* implicit=*/ true , ctor->getInitKind (),
7402
7402
/* required=*/ false , ctor->getObjCSelector (),
7403
7403
importedName, objcMethod->parameters (),
7404
- objcMethod->isVariadic (), redundant )) {
7404
+ objcMethod->isVariadic (), existing )) {
7405
7405
// If this is a compatibility stub, mark it as such.
7406
7406
if (correctSwiftName)
7407
7407
markAsVariant (newCtor, *correctSwiftName);
7408
7408
7409
7409
Impl.importAttributes (objcMethod, newCtor, curObjCClass);
7410
7410
newMembers.push_back (newCtor);
7411
+ } else if (existing && existing->getClangDecl ()) {
7412
+ // Check that the existing constructor the prevented new creation is
7413
+ // really an inherited factory initializer and not a class member.
7414
+ auto existingMD = cast<clang::ObjCMethodDecl>(existing->getClangDecl ());
7415
+ if (existingMD->getClassInterface () != curObjCClass) {
7416
+ newMembers.push_back (existing);
7417
+ }
7411
7418
}
7412
7419
continue ;
7413
7420
}
0 commit comments