@@ -2526,26 +2526,26 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25262526 [&]{
25272527 Printer.printName (decl->getName (), getTypeMemberPrintNameContext (decl));
25282528 });
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);
25362529
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);
25382537
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);
25452539
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 ());
25492549
25502550 printAccessors (decl);
25512551}
@@ -2674,18 +2674,13 @@ void PrintAST::printFunctionParameters(AbstractFunctionDecl *AFD) {
26742674 auto curTy = AFD->getInterfaceType ();
26752675
26762676 // 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 ();
26822680
26832681 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 ();
26892684
26902685 printParameterList (BodyParams, parameterListTypes,
26912686 AFD->argumentNameIsAPIByDefault ());
@@ -2878,15 +2873,14 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) {
28782873
28792874
28802875 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 ();
28902884 }
28912885
28922886 // @escaping is not valid in enum element position, even though the
@@ -2977,11 +2971,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
29772971 }, [&] { // Parameters
29782972 printGenericDeclGenericParams (decl);
29792973 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 ();
29852978 }
29862979 printParameterList (decl->getIndices (), params,
29872980 /* isAPINameByDefault*/ false );
0 commit comments