Skip to content

Commit e54b871

Browse files
committed
[SourceKit] Don’t transform type when printing if CurrentType can’t have members
Since 9ba892c we always transform `CurrentType` in `ASTPrinter` to be an interface type. This causes issues when the variable type is a generic parameter type. Previously we had `CurrentType` set to a `PrimaryArchetypeType`. With the fix in d93ae06, we are mapping the archetype out of context to a `GenericParamType`. A `GenericParamType`, however, can’t have members, so we’re hitting an assertion when creating a `TypeTransformContext`. Since the entire type transformation in `printTransformedTypeWithOptions` is only affecting type members, we should be able to safely skip over the transformation if `CurrentType` can’t have any members. Fixes rdar://76750555 [SR-14497]
1 parent 47ca24d commit e54b871

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
755755
void printType(Type T) { printTypeWithOptions(T, Options); }
756756

757757
void printTransformedTypeWithOptions(Type T, PrintOptions options) {
758-
if (CurrentType && Current) {
758+
if (CurrentType && Current && CurrentType->mayHaveMembers()) {
759759
if (T->hasArchetype()) {
760760
// Get the interface type, since TypeLocs still have
761761
// contextual types in them.

test/SourceKit/CursorInfo/cursor_generics.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ class MyType<T> {
1919
}
2020
}
2121

22+
// rdar://76750555
23+
public protocol IP {
24+
init(networkBytes: Int)
25+
}
26+
27+
public struct HostRecord<IPType: IP> {
28+
func foo() {
29+
let ipType = IPType(networkBytes: 42)
30+
}
31+
}
32+
2233
// RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- %s | %FileCheck -check-prefix=CHECK1 %s
2334
// CHECK1: <Declaration>func testGenerics&lt;T&gt;(x: <Type usr="s:15cursor_generics12testGenerics1xyx_tlF1TL_xmfp">T</Type>)</Declaration>
2435

@@ -37,3 +48,7 @@ class MyType<T> {
3748
// RUN: %sourcekitd-test -req=cursor -pos=18:14 %s -- %s | %FileCheck -check-prefix=CHECK5 %s
3849
// CHECK5: source.lang.swift.ref.var.instance
3950
// CHECK5: <Declaration>let items: [<Type usr="s:Si">Int</Type>]</Declaration>
51+
52+
// RUN: %sourcekitd-test -req=cursor -pos=29:22 %s -- %s | %FileCheck -check-prefix=CHECK_IP_TYPE %s
53+
// CHECK_IP_TYPE: source.lang.swift.ref.generic_type_param
54+
// CHECK_IP_TYPE: <Declaration>IPType : <Type usr="s:15cursor_generics2IPP">IP</Type></Declaration>

0 commit comments

Comments
 (0)