-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathdecls.swift
356 lines (299 loc) · 6.18 KB
/
decls.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency -enable-experimental-feature ParserASTGen \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %sanitize-address > %t/astgen.ast
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency \
// RUN: -enable-experimental-feature CoroutineAccessors \
// RUN: | %sanitize-address > %t/cpp-parser.ast
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-concurrency -enable-experimental-feature CoroutineAccessors -enable-experimental-feature ParserASTGen)
// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_CoroutineAccessors
// rdar://116686158
// UNSUPPORTED: asan
// NB: Ridiculous formatting to test that we do not include leading trivia in locations.
import
Swift
import typealias Swift.Codable
import enum Swift.Optional
import struct Swift.Array
import class Swift.KeyPath
import protocol Swift.Sequence
import func Swift.max
import var Swift._playgroundPrintHook
func
test1
(
y
x: Int, fn: (Int) -> Int
)
async
throws
->
Int {
return 0
}
func test2(y: Int = 0, oi: Int? = nil) -> Int {
let x =
y
return x
}
func test3(_ b: inout Bool) {
b = true
}
func testInOutClosureParam() -> (inout (Int, String)) -> Void {
return { (arg: inout (Int, String)) in
arg.1 = "rewritten"
}
}
func test4(_ i: _const Int) {
}
func test5(_ value: Any) { }
func test6<T>(t: T) where T: Proto1 {}
func test7() {
var binding1 = 0, binding2 = ""
}
func test8(_: Int) {}
func test9() -> Int { 0 }
func testVars() {
var a = 0
var b: Int = 0
var c, d: Int
var e, f: Int, g, h, i: String
let j: Int = 0, k: String = ""
var l: Int { 0 }
var m: Int { get { 0 } }
var n: Int {
get { return m }
set {}
}
var o: Int = 0 {
willSet {
n = newValue
}
}
var p: Int {
get { return 0 }
set(foo) {
o = foo
}
}
var q: Int = 0 {
didSet(old) {
p = old
}
}
var r: Int {
_read { yield q }
_modify { yield &q }
}
var s: Int {
get async throws { return 0 }
}
var t: Int {
read { yield q }
modify { yield &q }
}
}
func rethrowingFn(fn: () throws -> Void) rethrows {}
func reasyncFn(fn: () async -> Void) reasync {}
func testRethrows() {
rethrowingFn { _ = 1 }
// FIXME: Assertion failed: (isAsync()), function getAsyncContext, file GenCall.cpp, line 215.
// reasyncFn { _ = 1 }
}
struct TestVars {
var a = 0
var b: Int = 0
var c, d: Int
var e, f: Int, g, h, i: String
let j: Int = 0, k: String = ""
var l: Int { 0 }
var m: Int { get { 0 } }
var n: Int {
get { return m }
set {}
}
var o: Int = 0 {
willSet {
n = newValue
}
}
var p: Int {
get { return 0 }
set(foo) {
o = foo
}
}
var q: Int = 0 {
didSet(old) {
p = old
}
}
var r: Int {
_read { yield q }
_modify { yield &q }
}
var s: Int {
get async throws { return 0 }
}
private(set) var testPrivateSet = 1
}
extension TestVars {
var inExt: Int { return 0 }
}
struct TestSubscripts {
subscript(x: Int) -> Int {
0
}
subscript(y x: Int) -> Int {
get {
return 0
}
set(x) {}
}
subscript<I: Proto3, J: Proto3>(i: I, j: J) -> Int where I.A == J.B {
1
}
}
protocol Proto1 {}
protocol Proto2 {}
protocol
Proto3
<
A,
B
>: Proto1 where Self: Proto2 {
associatedtype
A where B: Proto1
associatedtype B: Equatable
=
Int
func method(_ b: Bool)
}
typealias
Alias<T>
=
String where T: Proto1
enum
Enum<T>: Int, Proto1 where T: Proto1 {
case
a
=
1
case b = 2,
c
func method(_ b: Bool) {}
}
enum WithPayload {
case a(
b: Int
), c(
d: Bool = false
)
}
struct
Struct
<
T1:
Proto1,
T2:
Proto2
>
:
Proto1, Proto2, @unchecked Sendable
where
T1
:
Proto3,
T1.A
==
Int
{
/*static*/ func method(_ b: Bool) {}
}
class
Class<T>: Proto1 where T: Proto3 {
func method(_ b: Bool) {}
deinit {
if true {}
}
init?<U>(_ u: U) where U: Proto1 {
if true {}
}
init!(i: Int) {}
}
actor
Actor<T>: Proto1 where T: Proto1 {
func method(_ b: Bool) {}
}
extension
Class: Proto2 where T: Proto1 {
func method2(_ b: Bool) {}
}
prefix
operator ⎭^-^⎭
infix
operator
~^-^~
:
AdditionPrecedence
postfix
operator ⎩^-^⎩
precedencegroup Precedence1 {
}
precedencegroup Precedence2 {
lowerThan: BitwiseShiftPrecedence, MultiplicationPrecedence
higherThan: Precedence1, AdditionPrecedence
associativity: left
assignment: true
}
struct TestStruct {
func method(arg: Int, _ c: Int) {}
// FIXME: Compute 'static' location
// static var shared = TestStruct()
// func testUnresolvedMember1() -> Self {
// return .shared
// }
//
// FIXME: Compute 'static' location
// static func instance(arg: Int) -> TestStruct { return TestStruct() }
}
struct ValueStruct<let N: Int> {}
func genericTest1<T>(_: T) {}
func genericTest2<each T>(_: repeat each T) {}
func genericTest4<let T: Int>(_: ValueStruct<T>) {}
func concreteValueTest1(_: ValueStruct<123>) {}
func concreteValueTest2(_: ValueStruct<-123>) {}
extension ValueStruct where N == 123 {}
extension ValueStruct where 123 == N {}
extension ValueStruct where N == -123 {}
extension ValueStruct where -123 == N {}
func testMagicIdentifier(file: String = #file, line: Int = #line) {
let _: String = file
let _: Int = line
}
class StaticTest {
class var classVar: Int { 42 }
static let staticVar = 42
}
func defaultArgInitTestFunc(fn: () -> () = {}) {}
struct DefaultArgInitTestStruct {
func foo(fn: () -> () = {}) {}
}
enum DefaultArgInitTestEnum {
case foo(x: () -> () = {})
}
@resultBuilder
struct MyBuilder {
static func buildBlock(_ items: Any...) -> [Any] { items }
}
func acceptBuilder(@MyBuilder fn: () -> [Any]) -> [Any] { fn() }
func testBuilder() {
let _: [Any] = acceptBuilder {
1
}
}
struct ExpansionRequirementTest<each T> where repeat each T: Comparable {}