@@ -2535,7 +2535,11 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25352535}
25362536
25372537void PrintAST::visitParamDecl (ParamDecl *decl) {
2538- return visitVarDecl (decl);
2538+ // Set and restore in-parameter-position printing of types
2539+ auto prior = Options.PrintAsInParamType ;
2540+ Options.PrintAsInParamType = true ;
2541+ visitVarDecl (decl);
2542+ Options.PrintAsInParamType = prior;
25392543}
25402544
25412545void PrintAST::printOneParameter (const ParamDecl *param, bool Curried,
@@ -2589,7 +2593,11 @@ void PrintAST::printOneParameter(const ParamDecl *param, bool Curried,
25892593 TheTypeLoc.setType (BGT->getGenericArgs ()[0 ]);
25902594 }
25912595
2596+ // Set and restore in-parameter-position printing of types
2597+ auto prior = Options.PrintAsInParamType ;
2598+ Options.PrintAsInParamType = true ;
25922599 printTypeLoc (TheTypeLoc);
2600+ Options.PrintAsInParamType = prior;
25932601
25942602 if (param->isVariadic ())
25952603 Printer << " ..." ;
@@ -3313,6 +3321,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
33133321 const PrintOptions &Options;
33143322 Optional<std::vector<GenericParamList *>> UnwrappedGenericParams;
33153323
3324+ // / Whether we are printing something in a function parameter position, and
3325+ // / thus want to print @escaping if it escapes.
3326+ bool inParameterPrinting;
3327+
33163328 void printDeclContext (DeclContext *DC) {
33173329 switch (DC->getContextKind ()) {
33183330 case DeclContextKind::Module: {
@@ -3480,7 +3492,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
34803492
34813493public:
34823494 TypePrinter (ASTPrinter &Printer, const PrintOptions &PO)
3483- : Printer(Printer), Options(PO) {}
3495+ : Printer(Printer), Options(PO),
3496+ inParameterPrinting (Options.PrintAsInParamType) {}
34843497
34853498 void visit (Type T) {
34863499 Printer.printTypePre (TypeLoc::withoutLoc (T));
@@ -3745,11 +3758,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37453758 Printer << " @autoclosure " ;
37463759 else
37473760 Printer << " @autoclosure(escaping) " ;
3748- } else if (info.isNoEscape ()) {
3749- // autoclosure implies noescape.
3750- Printer << " @noescape " ;
3751- } else if (info.isExplicitlyEscaping ()) {
3752- Printer << " @escaping " ;
3761+ } else if (inParameterPrinting) {
3762+ if (!info.isNoEscape ()) {
3763+ Printer << " @escaping " ;
3764+ }
37533765 }
37543766
37553767 if (Options.PrintFunctionRepresentationAttrs ) {
@@ -3841,8 +3853,17 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38413853
38423854 if (needsParens)
38433855 Printer << " (" ;
3844-
3856+
3857+ // Set in-parameter-position printing to print our parameters, then unset it
3858+ // for the return type (in case it is also a function), and restore at the
3859+ // end.
3860+ auto prior = inParameterPrinting;
3861+ inParameterPrinting = true ;
38453862 visit (inputType);
3863+ inParameterPrinting = false ;
3864+ SWIFT_DEFER {
3865+ inParameterPrinting = prior;
3866+ };
38463867
38473868 if (needsParens)
38483869 Printer << " )" ;
0 commit comments