@@ -182,6 +182,24 @@ static bool shouldPrintAllSemanticDetails(const PrintOptions &options) {
182
182
return false ;
183
183
}
184
184
185
+ // / Forces printing types with the `some` keyword, instead of the full stable
186
+ // / reference.
187
+ struct PrintWithOpaqueResultTypeKeywordRAII {
188
+ PrintWithOpaqueResultTypeKeywordRAII (PrintOptions &Options)
189
+ : Options(Options) {
190
+ SavedMode = Options.OpaqueReturnTypePrinting ;
191
+ Options.OpaqueReturnTypePrinting =
192
+ PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword;
193
+ }
194
+ ~PrintWithOpaqueResultTypeKeywordRAII () {
195
+ Options.OpaqueReturnTypePrinting = SavedMode;
196
+ }
197
+
198
+ private:
199
+ PrintOptions &Options;
200
+ PrintOptions::OpaqueReturnTypePrintingMode SavedMode;
201
+ };
202
+
185
203
PrintOptions PrintOptions::printSwiftInterfaceFile (ModuleDecl *ModuleToPrint,
186
204
bool preferTypeRepr,
187
205
bool printFullConvention,
@@ -3745,13 +3763,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
3745
3763
}
3746
3764
Printer.printDeclResultTypePre (decl, tyLoc);
3747
3765
3748
- // HACK: When printing result types for vars with opaque result types,
3749
- // always print them using the `some` keyword instead of printing
3750
- // the full stable reference.
3751
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
3752
- x (Options.OpaqueReturnTypePrinting ,
3753
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
3754
-
3766
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
3755
3767
printTypeLocForImplicitlyUnwrappedOptional (
3756
3768
tyLoc, decl->isImplicitlyUnwrappedOptional ());
3757
3769
}
@@ -4127,13 +4139,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
4127
4139
}
4128
4140
}
4129
4141
4130
- // HACK: When printing result types for funcs with opaque result types,
4131
- // always print them using the `some` keyword instead of printing
4132
- // the full stable reference.
4133
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
4134
- x (Options.OpaqueReturnTypePrinting ,
4135
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
4136
-
4142
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
4137
4143
printTypeLocForImplicitlyUnwrappedOptional (
4138
4144
ResultTyLoc, decl->isImplicitlyUnwrappedOptional ());
4139
4145
Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
@@ -4283,13 +4289,7 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
4283
4289
Printer.printDeclResultTypePre (decl, elementTy);
4284
4290
Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
4285
4291
4286
- // HACK: When printing result types for subscripts with opaque result types,
4287
- // always print them using the `some` keyword instead of printing
4288
- // the full stable reference.
4289
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
4290
- x (Options.OpaqueReturnTypePrinting ,
4291
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
4292
-
4292
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
4293
4293
printTypeLocForImplicitlyUnwrappedOptional (
4294
4294
elementTy, decl->isImplicitlyUnwrappedOptional ());
4295
4295
Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
0 commit comments