@@ -4306,12 +4306,12 @@ namespace {
4306
4306
// "raw" name will be imported as unavailable with a more helpful and
4307
4307
// specific message.
4308
4308
++NumFactoryMethodsAsInitializers;
4309
- bool redundant = false ;
4309
+ ConstructorDecl *existing = nullptr ;
4310
4310
auto result =
4311
4311
importConstructor (decl, dc, false , importedName.getInitKind (),
4312
4312
/* required=*/ false , selector, importedName,
4313
4313
{decl->param_begin (), decl->param_size ()},
4314
- decl->isVariadic (), redundant );
4314
+ decl->isVariadic (), existing );
4315
4315
4316
4316
if (!isActiveSwiftVersion () && result)
4317
4317
markAsVariant (result, *correctSwiftName);
@@ -4555,7 +4555,7 @@ namespace {
4555
4555
ImportedName importedName,
4556
4556
ArrayRef<const clang::ParmVarDecl*> args,
4557
4557
bool variadic,
4558
- bool &redundant );
4558
+ ConstructorDecl *&existing );
4559
4559
4560
4560
void recordObjCOverride (SubscriptDecl *subscript);
4561
4561
@@ -6234,11 +6234,11 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6234
6234
variadic = false ;
6235
6235
}
6236
6236
6237
- bool redundant ;
6237
+ ConstructorDecl *existing ;
6238
6238
auto result = importConstructor (objcMethod, dc, implicit,
6239
6239
kind.getValueOr (importedName.getInitKind ()),
6240
6240
required, selector, importedName, params,
6241
- variadic, redundant );
6241
+ variadic, existing );
6242
6242
6243
6243
// If this is a compatibility stub, mark it as such.
6244
6244
if (result && correctSwiftName)
@@ -6350,8 +6350,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6350
6350
const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
6351
6351
CtorInitializerKind kind, bool required, ObjCSelector selector,
6352
6352
ImportedName importedName, ArrayRef<const clang::ParmVarDecl *> args,
6353
- bool variadic, bool &redundant ) {
6354
- redundant = false ;
6353
+ bool variadic, ConstructorDecl *&existing ) {
6354
+ existing = nullptr ;
6355
6355
6356
6356
// Figure out the type of the container.
6357
6357
auto ownerNominal = dc->getSelfNominalTypeDecl ();
@@ -6451,7 +6451,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
6451
6451
6452
6452
// Otherwise, we shouldn't create a new constructor, because
6453
6453
// it will be no better than the existing one.
6454
- redundant = true ;
6454
+ existing = ctor ;
6455
6455
return nullptr ;
6456
6456
}
6457
6457
@@ -7388,19 +7388,26 @@ void SwiftDeclConverter::importInheritedConstructors(
7388
7388
!correctSwiftName &&
7389
7389
" Import inherited initializers never references correctSwiftName" );
7390
7390
importedName.setHasCustomName ();
7391
- bool redundant ;
7391
+ ConstructorDecl *existing ;
7392
7392
if (auto newCtor =
7393
7393
importConstructor (objcMethod, classDecl,
7394
7394
/* implicit=*/ true , ctor->getInitKind (),
7395
7395
/* required=*/ false , ctor->getObjCSelector (),
7396
7396
importedName, objcMethod->parameters (),
7397
- objcMethod->isVariadic (), redundant )) {
7397
+ objcMethod->isVariadic (), existing )) {
7398
7398
// If this is a compatibility stub, mark it as such.
7399
7399
if (correctSwiftName)
7400
7400
markAsVariant (newCtor, *correctSwiftName);
7401
7401
7402
7402
Impl.importAttributes (objcMethod, newCtor, curObjCClass);
7403
7403
newMembers.push_back (newCtor);
7404
+ } else if (existing && existing->getClangDecl ()) {
7405
+ // Check that the existing constructor the prevented new creation is
7406
+ // really an inherited factory initializer and not a class member.
7407
+ auto existingMD = cast<clang::ObjCMethodDecl>(existing->getClangDecl ());
7408
+ if (existingMD->getClassInterface () != curObjCClass) {
7409
+ newMembers.push_back (existing);
7410
+ }
7404
7411
}
7405
7412
continue ;
7406
7413
}
0 commit comments