Skip to content

[SourceKit] Don’t transform type when printing if CurrentType can’t have members #36989

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 27, 2021
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 @@ -755,7 +755,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
void printType(Type T) { printTypeWithOptions(T, Options); }

void printTransformedTypeWithOptions(Type T, PrintOptions options) {
if (CurrentType && Current) {
if (CurrentType && Current && CurrentType->mayHaveMembers()) {
if (T->hasArchetype()) {
// Get the interface type, since TypeLocs still have
// contextual types in them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if the mapTypeOutOfContext() is needed at all...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to be not. I’ll set up a follow-up PR removing it.

Expand Down
15 changes: 15 additions & 0 deletions test/SourceKit/CursorInfo/cursor_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ class MyType<T> {
}
}

// rdar://76750555
public protocol IP {
init(networkBytes: Int)
}

public struct HostRecord<IPType: IP> {
func foo() {
let ipType = IPType(networkBytes: 42)
}
}

// RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- %s | %FileCheck -check-prefix=CHECK1 %s
// CHECK1: <Declaration>func testGenerics&lt;T&gt;(x: <Type usr="s:15cursor_generics12testGenerics1xyx_tlF1TL_xmfp">T</Type>)</Declaration>

Expand All @@ -37,3 +48,7 @@ class MyType<T> {
// RUN: %sourcekitd-test -req=cursor -pos=18:14 %s -- %s | %FileCheck -check-prefix=CHECK5 %s
// CHECK5: source.lang.swift.ref.var.instance
// CHECK5: <Declaration>let items: [<Type usr="s:Si">Int</Type>]</Declaration>

// RUN: %sourcekitd-test -req=cursor -pos=29:22 %s -- %s | %FileCheck -check-prefix=CHECK_IP_TYPE %s
// CHECK_IP_TYPE: source.lang.swift.ref.generic_type_param
// CHECK_IP_TYPE: <Declaration>IPType : <Type usr="s:15cursor_generics2IPP">IP</Type></Declaration>