Files
swift-mirror/test/SourceKit/CursorInfo/cursor_generics.swift
Alex Hoppen 6b5c03208d [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]
2021-04-21 11:53:06 +02:00

55 lines
1.7 KiB
Swift

func testGenerics<T>(x: T) {
}
/// Doc Comment...
func testGenericsWithComment<T>(x: T) {
}
func someFunc <A>() -> A {
fatalError()
}
// rdar://problem/36871908
class MyType<T> {
let test: Bool = false
let items: [Int] = []
func myMethod() {
if test {}
for i in items {}
}
}
// 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>
// RUN: %sourcekitd-test -req=cursor -pos=5:10 %s -- %s | %FileCheck -check-prefix=CHECK2 %s
// CHECK2: <Function
// CHECK2: <Declaration>func testGenericsWithComment&lt;T&gt;(x: T)</Declaration>
// RUN: %sourcekitd-test -req=cursor -pos=8:16 %s -- %s | %FileCheck -check-prefix=CHECK3 %s
// CHECK3: source.lang.swift.decl.generic_type_param
// CHECK3: <Declaration>A</Declaration>
// RUN: %sourcekitd-test -req=cursor -pos=17:8 %s -- %s | %FileCheck -check-prefix=CHECK4 %s
// CHECK4: source.lang.swift.ref.var.instance
// CHECK4: <Declaration>let test: <Type usr="s:Sb">Bool</Type></Declaration>
// 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>