Skip to content

[5.3][ASTPrinter][SourceKit] Print 'Any' as a keyword. #31402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4349,7 +4349,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
if (T->hasExplicitAnyObject())
Printer << "AnyObject";
else
Printer << "Any";
Printer.printKeyword("Any", Options);
} else {
interleave(T->getMembers(), [&](Type Ty) { visit(Ty); },
[&] { Printer << " & "; });
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/TypeRepr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ CompositionTypeRepr *CompositionTypeRepr::create(const ASTContext &C,
void CompositionTypeRepr::printImpl(ASTPrinter &Printer,
const PrintOptions &Opts) const {
if (getTypes().empty()) {
Printer << "Any";
Printer.printKeyword("Any", Opts);
} else {
interleave(getTypes(), [&](TypeRepr *T) { printTypeRepr(T, Printer, Opts);},
[&] { Printer << " & "; });
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_annotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func testGlobal() {
// GLOBAL_EXPR-DAG: Keyword[#function]/None: <name>#function</name>; name=#function
// GLOBAL_EXPR-DAG: Decl[Module]/None: <name>Swift</name>; name=Swift
// GLOBAL_EXPR-DAG: Decl[Struct]/OtherModule[Swift]: <name>Int</name>; name=Int
// GLOBAL_EXPR-DAG: Decl[FreeFunction]/OtherModule[Swift]: <name>print</name>(<callarg><callarg.label>_</callarg.label> <callarg.param>items</callarg.param>: <callarg.type>Any</callarg.type>...</callarg>, <callarg><callarg.label>to</callarg.label> <callarg.param>output</callarg.param>: &amp;<callarg.type><typeid.sys>TextOutputStream</typeid.sys></callarg.type></callarg>); name=print(items: Any..., to: &TextOutputStream)
// GLOBAL_EXPR-DAG: Decl[FreeFunction]/OtherModule[Swift]: <name>print</name>(<callarg><callarg.label>_</callarg.label> <callarg.param>items</callarg.param>: <callarg.type><keyword>Any</keyword></callarg.type>...</callarg>, <callarg><callarg.label>to</callarg.label> <callarg.param>output</callarg.param>: &amp;<callarg.type><typeid.sys>TextOutputStream</typeid.sys></callarg.type></callarg>); name=print(items: Any..., to: &TextOutputStream)
// GLOBAL_EXPR: End completions


Expand Down
6 changes: 6 additions & 0 deletions test/SourceKit/CursorInfo/cursor_info.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ enum E7: String {
case b = "\u{66}"
}

func checkAnyIsAKeyword(x: Any) {}

// REQUIRES: objc_interop
// RUN: %empty-directory(%t.tmp)
// RUN: %swiftc_driver -emit-module -o %t.tmp/FooSwiftModule.swiftmodule %S/Inputs/FooSwiftModule.swift
Expand Down Expand Up @@ -765,3 +767,7 @@ enum E7: String {

// RUN: %sourcekitd-test -req=cursor -pos=227:14 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %s | %FileCheck -check-prefix=CHECK94 %s
// CHECK94: <empty cursor info; internal diagnostic: "Resolved to incomplete expression or statement.">

// RUN: %sourcekitd-test -req=cursor -pos=231:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %s | %FileCheck -check-prefix=CHECK95 %s
// CHECK95: <Declaration>func checkAnyIsAKeyword(x: Any)</Declaration>
// CHECK95-NEXT: <decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>checkAnyIsAKeyword</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><syntaxtype.keyword>Any</syntaxtype.keyword></decl.var.parameter.type></decl.var.parameter>)</decl.function.free>
2 changes: 2 additions & 0 deletions test/SourceKit/DocSupport/Inputs/cake.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ public protocol P {
public extension P {
func bar() where Self: Equatable {}
}

public func shouldPrintAnyAsKeyword(x: Any) {}
48 changes: 24 additions & 24 deletions test/SourceKit/DocSupport/doc_clang_module.swift.response

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions test/SourceKit/DocSupport/doc_swift_module.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ extension S3 {

func genfoo<T1, T2>(x ix: T1, y iy: T2) where T1 : cake.Prot, T2 : cake.C1, T1.Element == Int

func shouldPrintAnyAsKeyword(x x: Any)


[
{
Expand Down Expand Up @@ -1918,6 +1920,31 @@ func genfoo<T1, T2>(x ix: T1, y iy: T2) where T1 : cake.Prot, T2 : cake.C1, T1.E
key.usr: "s:Si",
key.offset: 2408,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 2413,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 2418,
key.length: 23
},
{
key.kind: source.lang.swift.syntaxtype.argument,
key.offset: 2442,
key.length: 1
},
{
key.kind: source.lang.swift.syntaxtype.parameter,
key.offset: 2444,
key.length: 1
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 2447,
key.length: 3
}
]
[
Expand Down Expand Up @@ -3070,5 +3097,22 @@ func genfoo<T1, T2>(x ix: T1, y iy: T2) where T1 : cake.Prot, T2 : cake.C1, T1.E
key.length: 2
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.name: "shouldPrintAnyAsKeyword(x:)",
key.usr: "s:4cake23shouldPrintAnyAsKeyword1xyyp_tF",
key.offset: 2413,
key.length: 38,
key.fully_annotated_decl: "<decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>shouldPrintAnyAsKeyword</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>x</decl.var.parameter.argument_label>: <decl.var.parameter.type><syntaxtype.keyword>Any</syntaxtype.keyword></decl.var.parameter.type></decl.var.parameter>)</decl.function.free>",
key.entities: [
{
key.kind: source.lang.swift.decl.var.local,
key.keyword: "x",
key.name: "x",
key.offset: 2447,
key.length: 3
}
]
}
]