forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeName.swift
130 lines (100 loc) · 4.06 KB
/
TypeName.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test
// XFAIL: linux
class C {}
struct S {}
enum E {}
protocol P {}
protocol P2 {}
protocol AssociatedTypes {
typealias A
typealias B
typealias C
}
class Model : AssociatedTypes {
typealias A = C
typealias B = S
typealias C = E
}
struct Model2 : AssociatedTypes {
typealias A = C
typealias B = S
typealias C = E
}
class GC<T : AssociatedTypes> {}
struct GS<T : AssociatedTypes> {}
enum GE<T : AssociatedTypes> {}
class GC2<T : AssociatedTypes, U : AssociatedTypes> {}
func printTypeName(t: Any.Type) { print(_typeName(t)) }
printTypeName(Int.self) // CHECK: Swift.Int
printTypeName(C.self) // CHECK-NEXT: [[THIS:.*]].C
printTypeName(S.self) // CHECK-NEXT: [[THIS]].S
printTypeName(E.self) // CHECK-NEXT: [[THIS]].E
printTypeName(GC<Model>.self) // CHECK-NEXT: [[THIS]].GC<[[THIS]].Model>
printTypeName(GS<Model>.self) // CHECK-NEXT: [[THIS]].GS<[[THIS]].Model>
printTypeName(GE<Model>.self) // CHECK-NEXT: [[THIS]].GE<[[THIS]].Model>
printTypeName(GC2<Model, Model2>.self) // CHECK-NEXT: [[THIS]].GC2<[[THIS]].Model, [[THIS]].Model2>
printTypeName(P.self) // CHECK-NEXT: [[THIS]].P
typealias PP2 = protocol<P, P2>
printTypeName(PP2.self) // CHECK-NEXT: protocol<[[THIS]].P, [[THIS]].P2>
printTypeName(Any.self) // CHECK-NEXT: protocol<>
typealias F = () -> ()
typealias F2 = () -> () -> ()
typealias F3 = (() -> ()) -> ()
printTypeName(F.self) // CHECK-NEXT: () -> ()
printTypeName(F2.self) // CHECK-NEXT: () -> () -> ()
printTypeName(F3.self) // CHECK-NEXT: (() -> ()) -> ()
typealias B = @convention(block) () -> ()
typealias B2 = () -> @convention(block) () -> ()
typealias B3 = (@convention(block) () -> ()) -> ()
printTypeName(B.self) // CHECK-NEXT: @convention(block) () -> ()
printTypeName(B2.self) // CHECK-NEXT: () -> @convention(block) () -> ()
printTypeName(B3.self) // CHECK-NEXT: (@convention(block) () -> ()) -> ()
printTypeName(F.Type.self) // CHECK-NEXT: (() -> ()).Type
printTypeName(C.Type.self) // CHECK-NEXT: [[THIS]].C.Type
printTypeName(C.Type.Type.self) // CHECK-NEXT: [[THIS]].C.Type.Type
printTypeName(Any.Type.self) // CHECK-NEXT: protocol<>.Type
printTypeName(Any.Protocol.self) // CHECK-NEXT: protocol<>.Protocol
printTypeName(AnyObject.self) // CHECK-NEXT: {{^}}Swift.AnyObject{{$}}
printTypeName(AnyClass.self) // CHECK-NEXT: {{^}}Swift.AnyObject.Type{{$}}
printTypeName((AnyObject?).self) // CHECK-NEXT: {{^}}Swift.Optional<Swift.AnyObject>{{$}}
printTypeName(Void.self) // CHECK-NEXT: ()
typealias Tup = (Any, F, C)
printTypeName(Tup.self) // CHECK-NEXT: (protocol<>, () -> (), [[THIS]].C)
typealias IF = inout Int -> ()
typealias IF2 = inout Int -> inout Int -> ()
typealias IF3 = (inout Int -> ()) -> ()
typealias IF3a = (inout (Int -> ())) -> ()
typealias IF3b = inout (Int -> ()) -> ()
typealias IF3c = ((inout Int) -> ()) -> ()
typealias IF4 = inout (() -> ()) -> ()
typealias IF5 = (inout Int, Any) -> ()
printTypeName(IF.self) // CHECK-NEXT: inout Swift.Int -> ()
printTypeName(IF2.self) // CHECK-NEXT: inout Swift.Int -> inout Swift.Int -> ()
printTypeName(IF3.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
printTypeName(IF3a.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
printTypeName(IF3b.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
printTypeName(IF3c.self) // CHECK-NEXT: (inout Swift.Int -> ()) -> ()
printTypeName(IF4.self) // CHECK-NEXT: inout (() -> ()) -> ()
printTypeName(IF5.self) // CHECK-NEXT: (inout Swift.Int, protocol<>) -> ()
func curry1() {
}
func curry1Throws() throws {
}
func curry2() -> () -> () {
return curry1
}
func curry2Throws() throws -> () -> () {
return curry1
}
func curry3() -> () throws -> () {
return curry1Throws
}
func curry3Throws() throws -> () throws -> () {
return curry1Throws
}
printTypeName(curry1.dynamicType) // CHECK-NEXT: () -> ()
printTypeName(curry2.dynamicType) // CHECK-NEXT: () -> () -> ()
printTypeName(curry2Throws.dynamicType) // CHECK-NEXT: () throws -> () -> ()
printTypeName(curry3.dynamicType) // CHECK-NEXT: () -> () throws -> ()
printTypeName(curry3Throws.dynamicType) // CHECK-NEXT: () throws -> () throws -> ()