@@ -1476,6 +1476,27 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
14761476 }
14771477}
14781478
1479+ static bool checkDuplicatedMethodName (StringRef funcName,
1480+ const AccessorDecl *AD,
1481+ DeclAndTypePrinter &declAndTypePrinter,
1482+ raw_ostream &os) {
1483+ auto *&decl = declAndTypePrinter.getCxxDeclEmissionScope ()
1484+ .emittedAccessorMethodNames [funcName];
1485+
1486+ if (!decl) {
1487+ // This is the first time an accessor with this name has been emitted.
1488+ decl = AD;
1489+ } else if (decl != AD) {
1490+ // An accessor for another property had the same name.
1491+ os << " // skip emitting accessor method for \' "
1492+ << AD->getStorage ()->getBaseIdentifier ().str () << " \' . \' " << funcName
1493+ << " \' already declared.\n " ;
1494+ return false ;
1495+ }
1496+
1497+ return true ;
1498+ }
1499+
14791500void DeclAndTypeClangFunctionPrinter::printCxxMethod (
14801501 DeclAndTypePrinter &declAndTypePrinter,
14811502 const NominalTypeDecl *typeDeclContext, const AbstractFunctionDecl *FD,
@@ -1552,6 +1573,12 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
15521573 Type resultTy, bool isStatic, bool isDefinition,
15531574 std::optional<IRABIDetailsProvider::MethodDispatchInfo> dispatchInfo) {
15541575 assert (accessor->isSetter () || accessor->getParameters ()->size () == 0 );
1576+ std::string accessorName = remapPropertyName (accessor, resultTy);
1577+
1578+ if (!checkDuplicatedMethodName (accessorName, accessor, declAndTypePrinter,
1579+ os))
1580+ return ;
1581+
15551582 os << " " ;
15561583
15571584 FunctionSignatureModifiers modifiers;
@@ -1563,9 +1590,9 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
15631590 !isStatic && accessor->isGetter () && !isa<ClassDecl>(typeDeclContext);
15641591 modifiers.hasSymbolUSR = !isDefinition;
15651592 modifiers.symbolUSROverride = accessor->getStorage ();
1566- auto result = printFunctionSignature (
1567- accessor, signature, remapPropertyName (accessor, resultTy) , resultTy,
1568- FunctionSignatureKind::CxxInlineThunk, modifiers);
1593+ auto result =
1594+ printFunctionSignature ( accessor, signature, accessorName , resultTy,
1595+ FunctionSignatureKind::CxxInlineThunk, modifiers);
15691596 assert (!result.isUnsupported () && " C signature should be unsupported too!" );
15701597 declAndTypePrinter.printAvailability (os, accessor->getStorage ());
15711598 if (!isDefinition) {
0 commit comments