@@ -2526,26 +2526,26 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
2526
2526
[&]{
2527
2527
Printer.printName (decl->getName (), getTypeMemberPrintNameContext (decl));
2528
2528
});
2529
- if (auto type = decl->getInterfaceType ()) {
2530
- Printer << " : " ;
2531
- TypeLoc tyLoc;
2532
- if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr ())
2533
- tyLoc = TypeLoc (repr, type);
2534
- else
2535
- tyLoc = TypeLoc::withoutLoc (type);
2536
2529
2537
- Printer.printDeclResultTypePre (decl, tyLoc);
2530
+ auto type = decl->getInterfaceType ();
2531
+ Printer << " : " ;
2532
+ TypeLoc tyLoc;
2533
+ if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr ())
2534
+ tyLoc = TypeLoc (repr, type);
2535
+ else
2536
+ tyLoc = TypeLoc::withoutLoc (type);
2538
2537
2539
- // HACK: When printing result types for vars with opaque result types,
2540
- // always print them using the `some` keyword instead of printing
2541
- // the full stable reference.
2542
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2543
- x (Options.OpaqueReturnTypePrinting ,
2544
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2538
+ Printer.printDeclResultTypePre (decl, tyLoc);
2545
2539
2546
- printTypeLocForImplicitlyUnwrappedOptional (
2547
- tyLoc, decl->isImplicitlyUnwrappedOptional ());
2548
- }
2540
+ // HACK: When printing result types for vars with opaque result types,
2541
+ // always print them using the `some` keyword instead of printing
2542
+ // the full stable reference.
2543
+ llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
2544
+ x (Options.OpaqueReturnTypePrinting ,
2545
+ PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
2546
+
2547
+ printTypeLocForImplicitlyUnwrappedOptional (
2548
+ tyLoc, decl->isImplicitlyUnwrappedOptional ());
2549
2549
2550
2550
printAccessors (decl);
2551
2551
}
@@ -2674,18 +2674,13 @@ void PrintAST::printFunctionParameters(AbstractFunctionDecl *AFD) {
2674
2674
auto curTy = AFD->getInterfaceType ();
2675
2675
2676
2676
// Skip over the implicit 'self'.
2677
- if (AFD->hasImplicitSelfDecl ()) {
2678
- if (curTy)
2679
- if (auto funTy = curTy->getAs <AnyFunctionType>())
2680
- curTy = funTy->getResult ();
2681
- }
2677
+ if (AFD->hasImplicitSelfDecl ())
2678
+ if (auto funTy = curTy->getAs <AnyFunctionType>())
2679
+ curTy = funTy->getResult ();
2682
2680
2683
2681
ArrayRef<AnyFunctionType::Param> parameterListTypes;
2684
- if (curTy) {
2685
- if (auto funTy = curTy->getAs <AnyFunctionType>()) {
2686
- parameterListTypes = funTy->getParams ();
2687
- }
2688
- }
2682
+ if (auto funTy = curTy->getAs <AnyFunctionType>())
2683
+ parameterListTypes = funTy->getParams ();
2689
2684
2690
2685
printParameterList (BodyParams, parameterListTypes,
2691
2686
AFD->argumentNameIsAPIByDefault ());
@@ -2878,15 +2873,14 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) {
2878
2873
2879
2874
2880
2875
auto params = ArrayRef<AnyFunctionType::Param>();
2881
- if (auto type = elt->getInterfaceType ()) {
2882
- if (!elt->isInvalid ()) {
2883
- // Walk to the params of the associated values.
2884
- // (EnumMetaType) -> (AssocValues) -> Enum
2885
- params = type->castTo <AnyFunctionType>()
2886
- ->getResult ()
2887
- ->castTo <AnyFunctionType>()
2888
- ->getParams ();
2889
- }
2876
+ if (!elt->isInvalid ()) {
2877
+ // Walk to the params of the associated values.
2878
+ // (EnumMetaType) -> (AssocValues) -> Enum
2879
+ auto type = elt->getInterfaceType ();
2880
+ params = type->castTo <AnyFunctionType>()
2881
+ ->getResult ()
2882
+ ->castTo <AnyFunctionType>()
2883
+ ->getParams ();
2890
2884
}
2891
2885
2892
2886
// @escaping is not valid in enum element position, even though the
@@ -2977,11 +2971,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
2977
2971
}, [&] { // Parameters
2978
2972
printGenericDeclGenericParams (decl);
2979
2973
auto params = ArrayRef<AnyFunctionType::Param>();
2980
- if (auto type = decl->getInterfaceType ()) {
2981
- if (!decl->isInvalid ()) {
2982
- // Walk to the params of the subscript's indices.
2983
- params = type->castTo <AnyFunctionType>()->getParams ();
2984
- }
2974
+ if (!decl->isInvalid ()) {
2975
+ // Walk to the params of the subscript's indices.
2976
+ auto type = decl->getInterfaceType ();
2977
+ params = type->castTo <AnyFunctionType>()->getParams ();
2985
2978
}
2986
2979
printParameterList (decl->getIndices (), params,
2987
2980
/* isAPINameByDefault*/ false );
0 commit comments