@@ -4306,12 +4306,12 @@ namespace {
43064306 // "raw" name will be imported as unavailable with a more helpful and
43074307 // specific message.
43084308 ++NumFactoryMethodsAsInitializers;
4309- bool redundant = false ;
4309+ ConstructorDecl *existing = nullptr ;
43104310 auto result =
43114311 importConstructor (decl, dc, false , importedName.getInitKind (),
43124312 /* required=*/ false , selector, importedName,
43134313 {decl->param_begin (), decl->param_size ()},
4314- decl->isVariadic (), redundant );
4314+ decl->isVariadic (), existing );
43154315
43164316 if (!isActiveSwiftVersion () && result)
43174317 markAsVariant (result, *correctSwiftName);
@@ -4555,7 +4555,7 @@ namespace {
45554555 ImportedName importedName,
45564556 ArrayRef<const clang::ParmVarDecl*> args,
45574557 bool variadic,
4558- bool &redundant );
4558+ ConstructorDecl *&existing );
45594559
45604560 void recordObjCOverride (SubscriptDecl *subscript);
45614561
@@ -6234,11 +6234,11 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
62346234 variadic = false ;
62356235 }
62366236
6237- bool redundant ;
6237+ ConstructorDecl *existing ;
62386238 auto result = importConstructor (objcMethod, dc, implicit,
62396239 kind.getValueOr (importedName.getInitKind ()),
62406240 required, selector, importedName, params,
6241- variadic, redundant );
6241+ variadic, existing );
62426242
62436243 // If this is a compatibility stub, mark it as such.
62446244 if (result && correctSwiftName)
@@ -6350,8 +6350,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63506350 const clang::ObjCMethodDecl *objcMethod, const DeclContext *dc, bool implicit,
63516351 CtorInitializerKind kind, bool required, ObjCSelector selector,
63526352 ImportedName importedName, ArrayRef<const clang::ParmVarDecl *> args,
6353- bool variadic, bool &redundant ) {
6354- redundant = false ;
6353+ bool variadic, ConstructorDecl *&existing ) {
6354+ existing = nullptr ;
63556355
63566356 // Figure out the type of the container.
63576357 auto ownerNominal = dc->getSelfNominalTypeDecl ();
@@ -6451,7 +6451,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
64516451
64526452 // Otherwise, we shouldn't create a new constructor, because
64536453 // it will be no better than the existing one.
6454- redundant = true ;
6454+ existing = ctor ;
64556455 return nullptr ;
64566456 }
64576457
@@ -7388,19 +7388,26 @@ void SwiftDeclConverter::importInheritedConstructors(
73887388 !correctSwiftName &&
73897389 " Import inherited initializers never references correctSwiftName" );
73907390 importedName.setHasCustomName ();
7391- bool redundant ;
7391+ ConstructorDecl *existing ;
73927392 if (auto newCtor =
73937393 importConstructor (objcMethod, classDecl,
73947394 /* implicit=*/ true , ctor->getInitKind (),
73957395 /* required=*/ false , ctor->getObjCSelector (),
73967396 importedName, objcMethod->parameters (),
7397- objcMethod->isVariadic (), redundant )) {
7397+ objcMethod->isVariadic (), existing )) {
73987398 // If this is a compatibility stub, mark it as such.
73997399 if (correctSwiftName)
74007400 markAsVariant (newCtor, *correctSwiftName);
74017401
74027402 Impl.importAttributes (objcMethod, newCtor, curObjCClass);
74037403 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+ }
74047411 }
74057412 continue ;
74067413 }
0 commit comments