forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnominal_types.swift
144 lines (116 loc) · 2.45 KB
/
nominal_types.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// RUN: %target-swift-remoteast-test -enable-anonymous-context-mangled-names %s | %FileCheck %s
// REQUIRES: swift-remoteast-test
@_silgen_name("printMetadataType")
func printType(_: Any.Type)
@_silgen_name("stopRemoteAST")
func stopRemoteAST()
printType(Int.self)
// CHECK: Int
struct A {}
printType(A.self)
// CHECK: A
struct B {
struct Foo {}
}
printType(B.Foo.self)
// CHECK: B.Foo
extension B {
struct Bar {}
}
printType(B.Bar.self)
// CHECK: B.Bar
class C {
}
printType(C.self)
// CHECK: C
class D : C {
}
printType(D.self)
// CHECK: D
class E {
struct Foo {}
}
printType(E.Foo.self)
// CHECK: E.Foo
struct F {
class Foo {}
}
printType(F.Foo.self)
// CHECK: F.Foo
enum G {
case Gwhatever
struct Foo {}
struct Bar<T> {}
}
printType(G.self)
// CHECK: G
printType(G.Foo.self)
// CHECK: G.Foo
printType(G.Bar<A>.self)
// CHECK: G.Bar<A>
struct H<T, U> {
struct Foo {}
struct Bar<V, W> {}
}
printType(H<A,A>.self)
// CHECK: H<A, A>
printType(H<B.Foo, H<B, A>>.self)
// CHECK: H<B.Foo, H<B, A>>
printType(H<B, B>.Foo.self)
// CHECK: H<B, B>.Foo
printType(H<A, B>.Bar<B, A>.self)
// CHECK: H<A, B>.Bar<B, A>
class I<T> {}
printType(I<Int>.self)
// CHECK: I<Int>
protocol J {}
printType(J.self)
// CHECK: found type: J
printType(J.Protocol.self)
// CHECK: found type: J.Protocol
printType(J.Type.self)
// CHECK: found type: J.Type
protocol K {}
typealias JK = J & K
typealias KJ = K & J
printType(JK.self)
// CHECK: found type: J & K
printType(KJ.self)
// CHECK: found type: J & K
struct L {
private struct PrivateInner { }
private struct PrivateInnerGeneric<T> { }
static func testPrivate() {
// CHECK: L.PrivateInner
printType(L.PrivateInner.self)
// CHECK: L.PrivateInnerGeneric<Int>
printType(L.PrivateInnerGeneric<Int>.self)
// CHECK: L.PrivateInnerGeneric<String>
printType(L.PrivateInnerGeneric<String>.self)
}
}
L.testPrivate()
struct M<T, U> {
private struct Inner { }
private struct InnerGeneric<V> { }
static func testPrivate() {
// CHECK: M<Int, String>.Inner
printType(Inner.self)
// CHECK: M<Int, String>.InnerGeneric<Double>
printType(InnerGeneric<Double>.self)
// CHECK: M<Int, String>.InnerGeneric<(String, Int)>
printType(InnerGeneric<(U, T)>.self)
}
}
M<Int, String>.testPrivate()
struct N {
static func testPrivate() {
struct LocalStruct {
struct Inner { }
}
// CHECK: LocalStruct.Inner
printType(LocalStruct.Inner.self)
}
}
N.testPrivate()
stopRemoteAST()