From 6ce7e4ec7b7b448698c44d5321604cec17158113 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 14 Jun 2019 17:22:30 -0700 Subject: [PATCH] [ASTPrinter] Make sure to print `some` as a keyword rdar://50073494 --- lib/AST/ASTPrinter.cpp | 2 +- lib/AST/TypeRepr.cpp | 2 +- test/SourceKit/CursorInfo/cursor_some_type.swift | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/SourceKit/CursorInfo/cursor_some_type.swift diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 264ad9e5400dd..fa04af3eee88c 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -4216,7 +4216,7 @@ class TypePrinter : public TypeVisitor { void visitOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *T) { switch (Options.OpaqueReturnTypePrinting) { case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword: - Printer << "some "; + Printer.printKeyword("some", Options, /*Suffix=*/" "); LLVM_FALLTHROUGH; case PrintOptions::OpaqueReturnTypePrintingMode::WithoutOpaqueKeyword: { visit(T->getExistentialType()); diff --git a/lib/AST/TypeRepr.cpp b/lib/AST/TypeRepr.cpp index 332c9a8e16f82..90a203ab7180a 100644 --- a/lib/AST/TypeRepr.cpp +++ b/lib/AST/TypeRepr.cpp @@ -555,7 +555,7 @@ void ProtocolTypeRepr::printImpl(ASTPrinter &Printer, void OpaqueReturnTypeRepr::printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const { - Printer << "some "; + Printer.printKeyword("some", Opts, /*Suffix=*/" "); printTypeRepr(Constraint, Printer, Opts); } diff --git a/test/SourceKit/CursorInfo/cursor_some_type.swift b/test/SourceKit/CursorInfo/cursor_some_type.swift new file mode 100644 index 0000000000000..a47a3ea46bdb4 --- /dev/null +++ b/test/SourceKit/CursorInfo/cursor_some_type.swift @@ -0,0 +1,12 @@ +public class Base {} + +public protocol Proto {} + +public func foo() -> some Base & Proto { + class Derived: Base, Proto {} + return Derived() +} + +// RUN: %sourcekitd-test -req=cursor -pos=5:13 %s -- %s | %FileCheck %s +// CHECK: public func foo() -> some Base & Proto +// CHECK: public func foo() -> some Base & Proto