@@ -2516,8 +2516,10 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25162516 });
25172517 if (decl->hasType ()) {
25182518 Printer << " : " ;
2519- // Use the non-repr external type, but reuse the TypeLoc printing code.
2520- printTypeLoc (TypeLoc::withoutLoc (decl->getType ()));
2519+ auto tyLoc = decl->getTypeLoc ();
2520+ if (!tyLoc.getTypeRepr ())
2521+ tyLoc = TypeLoc::withoutLoc (decl->getType ());
2522+ printTypeLoc (tyLoc);
25212523 }
25222524
25232525 printAccessors (decl);
@@ -2777,10 +2779,19 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
27772779
27782780 Type ResultTy = decl->getResultType ();
27792781 if (ResultTy && !ResultTy->isVoid ()) {
2782+ TypeLoc ResultTyLoc = decl->getBodyResultTypeLoc ();
2783+ if (!ResultTyLoc.getTypeRepr ())
2784+ ResultTyLoc = TypeLoc::withoutLoc (ResultTy);
2785+ // FIXME: Hacky way to workaround the fact that 'Self' as return
2786+ // TypeRepr is not getting 'typechecked'. See
2787+ // \c resolveTopLevelIdentTypeComponent function in TypeCheckType.cpp.
2788+ if (auto *simId = dyn_cast_or_null<SimpleIdentTypeRepr>(ResultTyLoc.getTypeRepr ())) {
2789+ if (simId->getIdentifier ().str () == " Self" )
2790+ ResultTyLoc = TypeLoc::withoutLoc (ResultTy);
2791+ }
27802792 Printer << " -> " ;
2781- // Use the non-repr external type, but reuse the TypeLoc printing code.
27822793 Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
2783- printTypeLoc (TypeLoc::withoutLoc (ResultTy) );
2794+ printTypeLoc (ResultTyLoc );
27842795 Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
27852796 }
27862797 }
@@ -3233,6 +3244,9 @@ void Decl::print(raw_ostream &os) const {
32333244 options.FunctionDefinitions = true ;
32343245 options.TypeDefinitions = true ;
32353246 options.VarInitializers = true ;
3247+ // FIXME: Move all places where SIL printing is happening to explicit options.
3248+ // For example, see \c ProjectionPath::print.
3249+ options.PreferTypeRepr = false ;
32363250
32373251 print (os, options);
32383252}
@@ -3743,10 +3757,14 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37433757 if (Options.SkipAttributes )
37443758 return ;
37453759
3746- if (info.isAutoClosure ())
3747- Printer << " @autoclosure " ;
3748- if (inParameterPrinting && !info.isNoEscape ())
3749- Printer << " @escaping " ;
3760+ if (info.isAutoClosure ()) {
3761+ Printer.printAttrName (" @autoclosure" );
3762+ Printer << " " ;
3763+ }
3764+ if (inParameterPrinting && !info.isNoEscape ()) {
3765+ Printer.printAttrName (" @escaping" );
3766+ Printer << " " ;
3767+ }
37503768
37513769 if (Options.PrintFunctionRepresentationAttrs ) {
37523770 // TODO: coalesce into a single convention attribute.
0 commit comments