@@ -4313,12 +4313,12 @@ namespace {
43134313 // "raw" name will be imported as unavailable with a more helpful and
43144314 // specific message.
43154315 ++NumFactoryMethodsAsInitializers;
4316- bool redundant = false ;
4316+ ConstructorDecl *existing = nullptr ;
43174317 auto result =
43184318 importConstructor (decl, dc, false , importedName.getInitKind (),
43194319 /* required=*/ false , selector, importedName,
43204320 {decl->param_begin (), decl->param_size ()},
4321- decl->isVariadic (), redundant );
4321+ decl->isVariadic (), existing );
43224322
43234323 if (!isActiveSwiftVersion () && result)
43244324 markAsVariant (result, *correctSwiftName);
@@ -4562,7 +4562,7 @@ namespace {
45624562 ImportedName importedName,
45634563 ArrayRef<const clang::ParmVarDecl*> args,
45644564 bool variadic,
4565- bool &redundant );
4565+ ConstructorDecl *&existing );
45664566
45674567 void recordObjCOverride (SubscriptDecl *subscript);
45684568
@@ -6241,11 +6241,11 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
62416241 variadic = false ;
62426242 }
62436243
6244- bool redundant ;
6244+ ConstructorDecl *existing ;
62456245 auto result = importConstructor (objcMethod, dc, implicit,
62466246 kind.getValueOr (importedName.getInitKind ()),
62476247 required, selector, importedName, params,
6248- variadic, redundant );
6248+ variadic, existing );
62496249
62506250 // If this is a compatibility stub, mark it as such.
62516251 if (result && correctSwiftName)
@@ -6357,8 +6357,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63576357 const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
63586358 CtorInitializerKind kind, bool required, ObjCSelector selector,
63596359 ImportedName importedName, ArrayRef<const clang::ParmVarDecl *> args,
6360- bool variadic, bool &redundant ) {
6361- redundant = false ;
6360+ bool variadic, ConstructorDecl *&existing ) {
6361+ existing = nullptr ;
63626362
63636363 // Figure out the type of the container.
63646364 auto ownerNominal = dc->getSelfNominalTypeDecl ();
@@ -6458,7 +6458,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
64586458
64596459 // Otherwise, we shouldn't create a new constructor, because
64606460 // it will be no better than the existing one.
6461- redundant = true ;
6461+ existing = ctor ;
64626462 return nullptr ;
64636463 }
64646464
@@ -7395,19 +7395,26 @@ void SwiftDeclConverter::importInheritedConstructors(
73957395 !correctSwiftName &&
73967396 " Import inherited initializers never references correctSwiftName" );
73977397 importedName.setHasCustomName ();
7398- bool redundant ;
7398+ ConstructorDecl *existing ;
73997399 if (auto newCtor =
74007400 importConstructor (objcMethod, classDecl,
74017401 /* implicit=*/ true , ctor->getInitKind (),
74027402 /* required=*/ false , ctor->getObjCSelector (),
74037403 importedName, objcMethod->parameters (),
7404- objcMethod->isVariadic (), redundant )) {
7404+ objcMethod->isVariadic (), existing )) {
74057405 // If this is a compatibility stub, mark it as such.
74067406 if (correctSwiftName)
74077407 markAsVariant (newCtor, *correctSwiftName);
74087408
74097409 Impl.importAttributes (objcMethod, newCtor, curObjCClass);
74107410 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+ }
74117418 }
74127419 continue ;
74137420 }
0 commit comments