@@ -873,7 +873,8 @@ class DeclAndTypePrinter::Implementation
873873
874874 void printAbstractFunctionAsMethod (AbstractFunctionDecl *AFD,
875875 bool isClassMethod,
876- bool isNSUIntegerSubscript = false ) {
876+ bool isNSUIntegerSubscript = false ,
877+ const SubscriptDecl *SD = nullptr ) {
877878 printDocumentationComment (AFD);
878879
879880 Optional<ForeignAsyncConvention> asyncConvention =
@@ -910,10 +911,15 @@ class DeclAndTypePrinter::Implementation
910911 os, owningPrinter.prologueOS , owningPrinter.typeMapping ,
911912 owningPrinter.interopContext , owningPrinter);
912913 if (auto *accessor = dyn_cast<AccessorDecl>(AFD)) {
913- declPrinter.printCxxPropertyAccessorMethod (
914- typeDeclContext, accessor, funcABI->getSignature (),
915- funcABI->getSymbolName (), resultTy,
916- /* isDefinition=*/ false );
914+ if (SD)
915+ declPrinter.printCxxSubscriptAccessorMethod (
916+ typeDeclContext, accessor, funcABI->getSignature (),
917+ funcABI->getSymbolName (), resultTy, /* isDefinition=*/ false );
918+ else
919+ declPrinter.printCxxPropertyAccessorMethod (
920+ typeDeclContext, accessor, funcABI->getSignature (),
921+ funcABI->getSymbolName (), resultTy,
922+ /* isDefinition=*/ false );
917923 } else {
918924 declPrinter.printCxxMethod (typeDeclContext, AFD,
919925 funcABI->getSignature (),
@@ -927,11 +933,15 @@ class DeclAndTypePrinter::Implementation
927933 owningPrinter);
928934
929935 if (auto *accessor = dyn_cast<AccessorDecl>(AFD)) {
930-
931- defPrinter.printCxxPropertyAccessorMethod (
932- typeDeclContext, accessor, funcABI->getSignature (),
933- funcABI->getSymbolName (), resultTy,
934- /* isDefinition=*/ true );
936+ if (SD)
937+ defPrinter.printCxxSubscriptAccessorMethod (
938+ typeDeclContext, accessor, funcABI->getSignature (),
939+ funcABI->getSymbolName (), resultTy, /* isDefinition=*/ true );
940+ else
941+ defPrinter.printCxxPropertyAccessorMethod (
942+ typeDeclContext, accessor, funcABI->getSignature (),
943+ funcABI->getSymbolName (), resultTy,
944+ /* isDefinition=*/ true );
935945 } else {
936946 defPrinter.printCxxMethod (typeDeclContext, AFD, funcABI->getSignature (),
937947 funcABI->getSymbolName (), resultTy,
@@ -1818,8 +1828,14 @@ class DeclAndTypePrinter::Implementation
18181828 }
18191829
18201830 void visitSubscriptDecl (SubscriptDecl *SD) {
1821- if (outputLang == OutputLanguageMode::Cxx)
1831+ if (outputLang == OutputLanguageMode::Cxx) {
1832+ if (!SD->isInstanceMember ())
1833+ return ;
1834+ auto *getter = SD->getOpaqueAccessor (AccessorKind::Get);
1835+ printAbstractFunctionAsMethod (getter, false ,
1836+ /* isNSUIntegerSubscript=*/ false , SD);
18221837 return ;
1838+ }
18231839 assert (SD->isInstanceMember () && " static subscripts not supported" );
18241840
18251841 bool isNSUIntegerSubscript = false ;
0 commit comments