@@ -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,
@@ -1317,6 +1335,8 @@ void PrintAST::printTypedPattern(const TypedPattern *TP) {
1317
1335
printPattern (TP->getSubPattern ());
1318
1336
Printer << " : " ;
1319
1337
1338
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
1339
+
1320
1340
// Make sure to check if the underlying var decl is an implicitly unwrapped
1321
1341
// optional.
1322
1342
bool isIUO = false ;
@@ -3745,13 +3765,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
3745
3765
}
3746
3766
Printer.printDeclResultTypePre (decl, tyLoc);
3747
3767
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
-
3768
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
3755
3769
printTypeLocForImplicitlyUnwrappedOptional (
3756
3770
tyLoc, decl->isImplicitlyUnwrappedOptional ());
3757
3771
}
@@ -4127,13 +4141,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
4127
4141
}
4128
4142
}
4129
4143
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
-
4144
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
4137
4145
printTypeLocForImplicitlyUnwrappedOptional (
4138
4146
ResultTyLoc, decl->isImplicitlyUnwrappedOptional ());
4139
4147
Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
@@ -4283,13 +4291,7 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
4283
4291
Printer.printDeclResultTypePre (decl, elementTy);
4284
4292
Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
4285
4293
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
-
4294
+ PrintWithOpaqueResultTypeKeywordRAII x (Options);
4293
4295
printTypeLocForImplicitlyUnwrappedOptional (
4294
4296
elementTy, decl->isImplicitlyUnwrappedOptional ());
4295
4297
Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
0 commit comments