@@ -887,8 +887,10 @@ class PrintAST : public ASTVisitor<PrintAST> {
887887 printTransformedTypeWithOptions (T, Options);
888888 }
889889
890- void printTypeLocWithOptions (const TypeLoc &TL, const PrintOptions &options) {
890+ void printTypeLocWithOptions (const TypeLoc &TL, const PrintOptions &options,
891+ std::optional<llvm::function_ref<void ()>> printBeforeType = std::nullopt) {
891892 if (CurrentType && TL.getType ()) {
893+ if (printBeforeType) (*printBeforeType)();
892894 printTransformedTypeWithOptions (TL.getType (), options);
893895 return ;
894896 }
@@ -901,11 +903,21 @@ class PrintAST : public ASTVisitor<PrintAST> {
901903 return ;
902904 }
903905
906+ if (printBeforeType) (*printBeforeType)();
904907 TL.getType ().print (Printer, options);
905908 }
906909
907910 void printTypeLoc (const TypeLoc &TL) { printTypeLocWithOptions (TL, Options); }
908911
912+ // / Print a TypeLoc. If we decide to print based on the type, rather than
913+ // / based on the TypeRepr, call the given function before printing the type;
914+ // / this is useful if there are attributes in the TypeRepr which don't end
915+ // / up being part of the type, such as `@unchecked` in inheritance clauses.
916+ void printTypeLoc (const TypeLoc &TL,
917+ llvm::function_ref<void ()> printBeforeType) {
918+ printTypeLocWithOptions (TL, Options, printBeforeType);
919+ }
920+
909921 void printTypeLocForImplicitlyUnwrappedOptional (TypeLoc TL, bool IUO) {
910922 PrintOptions options = Options;
911923 options.PrintOptionalAsImplicitlyUnwrapped = IUO;
@@ -2710,15 +2722,15 @@ void PrintAST::printInherited(const Decl *decl) {
27102722 Printer << " : " ;
27112723
27122724 interleave (TypesToPrint, [&](InheritedEntry inherited) {
2713- if (inherited. isUnchecked ())
2714- Printer << " @unchecked " ;
2715- if (inherited. isRetroactive () &&
2716- ! llvm::is_contained (Options. ExcludeAttrList , TypeAttrKind::Retroactive))
2717- Printer << " @retroactive " ;
2718- if (inherited. isPreconcurrency ())
2719- Printer << " @preconcurrency " ;
2720-
2721- printTypeLoc (inherited );
2725+ printTypeLoc (inherited, [&] {
2726+ if (inherited. isUnchecked ())
2727+ Printer << " @unchecked " ;
2728+ if (inherited. isRetroactive () &&
2729+ ! llvm::is_contained (Options. ExcludeAttrList , TypeAttrKind::Retroactive))
2730+ Printer << " @retroactive " ;
2731+ if (inherited. isPreconcurrency ())
2732+ Printer << " @preconcurrency " ;
2733+ } );
27222734 }, [&]() {
27232735 Printer << " , " ;
27242736 });
0 commit comments