@@ -385,26 +385,43 @@ static bool isInPrivateOrLocalContext(const ValueDecl *D) {
385385 return isInPrivateOrLocalContext (nominal);
386386}
387387
388- static unsigned getUnnamedParamIndex (const Decl *D) {
389- unsigned UnnamedIndex = 0 ;
388+ static bool getUnnamedParamIndex (const ParameterList *ParamList,
389+ const ParamDecl *D,
390+ unsigned &UnnamedIndex) {
391+ for (auto Param : *ParamList) {
392+ if (!Param->hasName ()) {
393+ if (Param == D)
394+ return true ;
395+ ++UnnamedIndex;
396+ }
397+ }
398+ return false ;
399+ }
400+
401+ static unsigned getUnnamedParamIndex (const ParamDecl *D) {
402+ if (auto SD = dyn_cast<SubscriptDecl>(D->getDeclContext ())) {
403+ unsigned UnnamedIndex = 0 ;
404+ auto *ParamList = SD->getIndices ();
405+ if (getUnnamedParamIndex (ParamList, D, UnnamedIndex))
406+ return UnnamedIndex;
407+ llvm_unreachable (" param not found" );
408+ }
409+
390410 ArrayRef<ParameterList *> ParamLists;
391411
392412 if (auto AFD = dyn_cast<AbstractFunctionDecl>(D->getDeclContext ())) {
393413 ParamLists = AFD->getParameterLists ();
394- } else if (auto ACE = dyn_cast<AbstractClosureExpr>(D->getDeclContext ())) {
395- ParamLists = ACE->getParameterLists ();
396414 } else {
397- llvm_unreachable (" unhandled param context" );
415+ auto ACE = cast<AbstractClosureExpr>(D->getDeclContext ());
416+ ParamLists = ACE->getParameterLists ();
398417 }
418+
419+ unsigned UnnamedIndex = 0 ;
399420 for (auto ParamList : ParamLists) {
400- for (auto Param : *ParamList) {
401- if (!Param->hasName ()) {
402- if (Param == D)
403- return UnnamedIndex;
404- ++UnnamedIndex;
405- }
406- }
421+ if (getUnnamedParamIndex (ParamList, D, UnnamedIndex))
422+ return UnnamedIndex;
407423 }
424+
408425 llvm_unreachable (" param not found" );
409426}
410427
@@ -427,9 +444,11 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
427444 }
428445
429446 if (decl->getDeclContext ()->isLocalContext ()) {
430- if (isa<ParamDecl>(decl) && !decl->hasName ()) {
431- // Mangle unnamed params with their ordering.
432- return appendOperator (" L" , Index (getUnnamedParamIndex (decl)));
447+ if (auto *paramDecl = dyn_cast<ParamDecl>(decl)) {
448+ if (!decl->hasName ()) {
449+ // Mangle unnamed params with their ordering.
450+ return appendOperator (" L" , Index (getUnnamedParamIndex (paramDecl)));
451+ }
433452 }
434453 // Mangle local declarations with a numeric discriminator.
435454 return appendOperator (" L" , Index (decl->getLocalDiscriminator ()));
0 commit comments