-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathname_lookup.swift
660 lines (546 loc) · 29.3 KB
/
name_lookup.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
// RUN: %target-typecheck-verify-swift -typo-correction-limit 100
class ThisBase1 {
init() { }
var baseInstanceVar: Int
var baseProp : Int {
get {
return 42
}
set {}
}
func baseFunc0() {}
func baseFunc1(_ a: Int) {}
subscript(i: Int) -> Double {
get {
return Double(i)
}
set {
baseInstanceVar = i
}
}
class var baseStaticVar: Int = 42 // expected-error {{class stored properties not supported}}
class var baseStaticProp: Int {
get {
return 42
}
set {}
}
class func baseStaticFunc0() {}
struct BaseNestedStruct {} // expected-note {{did you mean 'BaseNestedStruct'?}}
class BaseNestedClass {
init() { }
}
enum BaseNestedUnion {
case BaseUnionX(Int)
}
typealias BaseNestedTypealias = Int // expected-note {{did you mean 'BaseNestedTypealias'?}}
}
class ThisDerived1 : ThisBase1 {
override init() { super.init() }
var derivedInstanceVar: Int
var derivedProp : Int {
get {
return 42
}
set {}
}
func derivedFunc0() {}
func derivedFunc1(_ a: Int) {}
subscript(i: Double) -> Int {
get {
return Int(i)
}
set {
baseInstanceVar = Int(i)
}
}
class var derivedStaticVar: Int = 42// expected-error {{class stored properties not supported}}
class var derivedStaticProp: Int {
get {
return 42
}
set {}
}
class func derivedStaticFunc0() {}
struct DerivedNestedStruct {}
class DerivedNestedClass {
init() { }
}
enum DerivedNestedUnion { // expected-note {{did you mean 'DerivedNestedUnion'?}}
case DerivedUnionX(Int)
}
typealias DerivedNestedTypealias = Int
func testSelf1() {
self.baseInstanceVar = 42
self.baseProp = 42
self.baseFunc0()
self.baseFunc1(42)
self[0] = 42.0
self.baseStaticVar = 42 // expected-error {{static member 'baseStaticVar' cannot be used on instance of type 'ThisDerived1'}}
self.baseStaticProp = 42 // expected-error {{static member 'baseStaticProp' cannot be used on instance of type 'ThisDerived1'}}
self.baseStaticFunc0() // expected-error {{static member 'baseStaticFunc0' cannot be used on instance of type 'ThisDerived1'}}
self.baseExtProp = 42
self.baseExtFunc0()
self.baseExtStaticVar = 42
self.baseExtStaticProp = 42
self.baseExtStaticFunc0() // expected-error {{static member 'baseExtStaticFunc0' cannot be used on instance of type 'ThisDerived1'}}
var bs1 : BaseNestedStruct
var bc1 : BaseNestedClass
var bo1 : BaseNestedUnion = .BaseUnionX(42)
var bt1 : BaseNestedTypealias
var bs2 = self.BaseNestedStruct() // expected-error{{static member 'BaseNestedStruct' cannot be used on instance of type 'ThisDerived1'}}
var bc2 = self.BaseNestedClass() // expected-error{{static member 'BaseNestedClass' cannot be used on instance of type 'ThisDerived1'}}
var bo2 = self.BaseUnionX(24) // expected-error {{value of type 'ThisDerived1' has no member 'BaseUnionX'}}
var bo3 = self.BaseNestedUnion.BaseUnionX(24) // expected-error{{static member 'BaseNestedUnion' cannot be used on instance of type 'ThisDerived1'}}
var bt2 = self.BaseNestedTypealias(42) // expected-error{{static member 'BaseNestedTypealias' cannot be used on instance of type 'ThisDerived1'}}
var bes1 : BaseExtNestedStruct
var bec1 : BaseExtNestedClass
var beo1 : BaseExtNestedUnion = .BaseExtUnionX(42)
var bet1 : BaseExtNestedTypealias
var bes2 = self.BaseExtNestedStruct() // expected-error{{static member 'BaseExtNestedStruct' cannot be used on instance of type 'ThisDerived1'}}
var bec2 = self.BaseExtNestedClass() // expected-error{{static member 'BaseExtNestedClass' cannot be used on instance of type 'ThisDerived1'}}
var beo2 = self.BaseExtUnionX(24) // expected-error {{value of type 'ThisDerived1' has no member 'BaseExtUnionX'}}
var beo3 = self.BaseExtNestedUnion.BaseExtUnionX(24) // expected-error{{static member 'BaseExtNestedUnion' cannot be used on instance of type 'ThisDerived1'}}
var bet2 = self.BaseExtNestedTypealias(42) // expected-error{{static member 'BaseExtNestedTypealias' cannot be used on instance of type 'ThisDerived1'}}
self.derivedInstanceVar = 42
self.derivedProp = 42
self.derivedFunc0()
self.derivedStaticVar = 42 // expected-error {{static member 'derivedStaticVar' cannot be used on instance of type 'ThisDerived1'}}
self.derivedStaticProp = 42 // expected-error {{static member 'derivedStaticProp' cannot be used on instance of type 'ThisDerived1'}}
self.derivedStaticFunc0() // expected-error {{static member 'derivedStaticFunc0' cannot be used on instance of type 'ThisDerived1'}}
self.derivedExtProp = 42
self.derivedExtFunc0()
self.derivedExtStaticVar = 42
self.derivedExtStaticProp = 42
self.derivedExtStaticFunc0() // expected-error {{static member 'derivedExtStaticFunc0' cannot be used on instance of type 'ThisDerived1'}}
var ds1 : DerivedNestedStruct
var dc1 : DerivedNestedClass
var do1 : DerivedNestedUnion = .DerivedUnionX(42)
var dt1 : DerivedNestedTypealias
var ds2 = self.DerivedNestedStruct() // expected-error{{static member 'DerivedNestedStruct' cannot be used on instance of type 'ThisDerived1'}}
var dc2 = self.DerivedNestedClass() // expected-error{{static member 'DerivedNestedClass' cannot be used on instance of type 'ThisDerived1'}}
var do2 = self.DerivedUnionX(24) // expected-error {{value of type 'ThisDerived1' has no member 'DerivedUnionX'}}
var do3 = self.DerivedNestedUnion.DerivedUnionX(24) // expected-error{{static member 'DerivedNestedUnion' cannot be used on instance of type 'ThisDerived1'}}
var dt2 = self.DerivedNestedTypealias(42) // expected-error{{static member 'DerivedNestedTypealias' cannot be used on instance of type 'ThisDerived1'}}
var des1 : DerivedExtNestedStruct
var dec1 : DerivedExtNestedClass
var deo1 : DerivedExtNestedUnion = .DerivedExtUnionX(42)
var det1 : DerivedExtNestedTypealias
var des2 = self.DerivedExtNestedStruct() // expected-error{{static member 'DerivedExtNestedStruct' cannot be used on instance of type 'ThisDerived1'}}
var dec2 = self.DerivedExtNestedClass() // expected-error{{static member 'DerivedExtNestedClass' cannot be used on instance of type 'ThisDerived1'}}
var deo2 = self.DerivedExtUnionX(24) // expected-error {{value of type 'ThisDerived1' has no member 'DerivedExtUnionX'}}
var deo3 = self.DerivedExtNestedUnion.DerivedExtUnionX(24) // expected-error{{static member 'DerivedExtNestedUnion' cannot be used on instance of type 'ThisDerived1'}}
var det2 = self.DerivedExtNestedTypealias(42) // expected-error{{static member 'DerivedExtNestedTypealias' cannot be used on instance of type 'ThisDerived1'}}
self.Type // expected-error {{value of type 'ThisDerived1' has no member 'Type'}}
}
func testSuper1() {
super.baseInstanceVar = 42
super.baseProp = 42
super.baseFunc0()
super.baseFunc1(42)
super[0] = 42.0
super.baseStaticVar = 42 // expected-error {{static member 'baseStaticVar' cannot be used on instance of type 'ThisBase1'}}
super.baseStaticProp = 42 // expected-error {{static member 'baseStaticProp' cannot be used on instance of type 'ThisBase1'}}
super.baseStaticFunc0() // expected-error {{static member 'baseStaticFunc0' cannot be used on instance of type 'ThisBase1'}}
super.baseExtProp = 42
super.baseExtFunc0()
super.baseExtStaticVar = 42
super.baseExtStaticProp = 42
super.baseExtStaticFunc0() // expected-error {{static member 'baseExtStaticFunc0' cannot be used on instance of type 'ThisBase1'}}
var bs2 = super.BaseNestedStruct() // expected-error{{static member 'BaseNestedStruct' cannot be used on instance of type 'ThisBase1'}}
var bc2 = super.BaseNestedClass() // expected-error{{static member 'BaseNestedClass' cannot be used on instance of type 'ThisBase1'}}
var bo2 = super.BaseUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'BaseUnionX'}}
var bo3 = super.BaseNestedUnion.BaseUnionX(24) // expected-error{{static member 'BaseNestedUnion' cannot be used on instance of type 'ThisBase1'}}
var bt2 = super.BaseNestedTypealias(42) // expected-error{{static member 'BaseNestedTypealias' cannot be used on instance of type 'ThisBase1'}}
var bes2 = super.BaseExtNestedStruct() // expected-error{{static member 'BaseExtNestedStruct' cannot be used on instance of type 'ThisBase1'}}
var bec2 = super.BaseExtNestedClass() // expected-error{{static member 'BaseExtNestedClass' cannot be used on instance of type 'ThisBase1'}}
var beo2 = super.BaseExtUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'BaseExtUnionX'}}
var beo3 = super.BaseExtNestedUnion.BaseExtUnionX(24) // expected-error{{static member 'BaseExtNestedUnion' cannot be used on instance of type 'ThisBase1'}}
var bet2 = super.BaseExtNestedTypealias(42) // expected-error{{static member 'BaseExtNestedTypealias' cannot be used on instance of type 'ThisBase1'}}
super.derivedInstanceVar = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedInstanceVar'}}
super.derivedProp = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedProp'}}
super.derivedFunc0() // expected-error {{value of type 'ThisBase1' has no member 'derivedFunc0'}}
super.derivedStaticVar = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedStaticVar'}}
super.derivedStaticProp = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedStaticProp'}}
super.derivedStaticFunc0() // expected-error {{value of type 'ThisBase1' has no member 'derivedStaticFunc0'}}
super.derivedExtProp = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedExtProp'}}
super.derivedExtFunc0() // expected-error {{value of type 'ThisBase1' has no member 'derivedExtFunc0'}}
super.derivedExtStaticVar = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedExtStaticVar'; did you mean 'baseExtStaticVar'?}}
super.derivedExtStaticProp = 42 // expected-error {{value of type 'ThisBase1' has no member 'derivedExtStaticProp'; did you mean 'baseExtStaticProp'?}}
super.derivedExtStaticFunc0() // expected-error {{value of type 'ThisBase1' has no member 'derivedExtStaticFunc0'}}
var ds2 = super.DerivedNestedStruct() // expected-error {{value of type 'ThisBase1' has no member 'DerivedNestedStruct'}}
var dc2 = super.DerivedNestedClass() // expected-error {{value of type 'ThisBase1' has no member 'DerivedNestedClass'}}
var do2 = super.DerivedUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'DerivedUnionX'}}
var do3 = super.DerivedNestedUnion.DerivedUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'DerivedNestedUnion'}}
var dt2 = super.DerivedNestedTypealias(42) // expected-error {{value of type 'ThisBase1' has no member 'DerivedNestedTypealias'}}
var des2 = super.DerivedExtNestedStruct() // expected-error {{value of type 'ThisBase1' has no member 'DerivedExtNestedStruct'}}
var dec2 = super.DerivedExtNestedClass() // expected-error {{value of type 'ThisBase1' has no member 'DerivedExtNestedClass'}}
var deo2 = super.DerivedExtUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'DerivedExtUnionX'}}
var deo3 = super.DerivedExtNestedUnion.DerivedExtUnionX(24) // expected-error {{value of type 'ThisBase1' has no member 'DerivedExtNestedUnion'}}
var det2 = super.DerivedExtNestedTypealias(42) // expected-error {{value of type 'ThisBase1' has no member 'DerivedExtNestedTypealias'}}
super.Type // expected-error {{value of type 'ThisBase1' has no member 'Type'}}
}
class func staticTestSelf1() {
self.baseInstanceVar = 42 // expected-error {{member 'baseInstanceVar' cannot be used on type 'ThisDerived1'}}
self.baseProp = 42 // expected-error {{member 'baseProp' cannot be used on type 'ThisDerived1'}}
self.baseFunc0() // expected-error {{instance member 'baseFunc0' cannot be used on type 'ThisDerived1'}}
self.baseFunc0(ThisBase1())() // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
self.baseFunc0(ThisDerived1())()
self.baseFunc1(42) // expected-error {{instance member 'baseFunc1' cannot be used on type 'ThisDerived1'}}
self.baseFunc1(ThisBase1())(42) // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
self.baseFunc1(ThisDerived1())(42)
self[0] = 42.0 // expected-error {{instance member 'subscript' cannot be used on type 'ThisDerived1'}}
self.baseStaticVar = 42
self.baseStaticProp = 42
self.baseStaticFunc0()
self.baseExtProp = 42 // expected-error {{member 'baseExtProp' cannot be used on type 'ThisDerived1'}}
self.baseExtFunc0() // expected-error {{instance member 'baseExtFunc0' cannot be used on type 'ThisDerived1'}}
self.baseExtStaticVar = 42 // expected-error {{instance member 'baseExtStaticVar' cannot be used on type 'ThisDerived1'}}
self.baseExtStaticProp = 42 // expected-error {{member 'baseExtStaticProp' cannot be used on type 'ThisDerived1'}}
self.baseExtStaticFunc0()
var bs1 : BaseNestedStruct
var bc1 : BaseNestedClass
var bo1 : BaseNestedUnion = .BaseUnionX(42)
var bt1 : BaseNestedTypealias
var bs2 = self.BaseNestedStruct()
var bc2 = self.BaseNestedClass()
var bo2 = self.BaseUnionX(24) // expected-error {{type 'ThisDerived1' has no member 'BaseUnionX'}}
var bo3 = self.BaseNestedUnion.BaseUnionX(24)
var bt2 = self.BaseNestedTypealias()
self.derivedInstanceVar = 42 // expected-error {{member 'derivedInstanceVar' cannot be used on type 'ThisDerived1'}}
self.derivedProp = 42 // expected-error {{member 'derivedProp' cannot be used on type 'ThisDerived1'}}
self.derivedFunc0() // expected-error {{instance member 'derivedFunc0' cannot be used on type 'ThisDerived1'}}
self.derivedFunc0(ThisBase1())() // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
self.derivedFunc0(ThisDerived1())()
self.derivedStaticVar = 42
self.derivedStaticProp = 42
self.derivedStaticFunc0()
self.derivedExtProp = 42 // expected-error {{member 'derivedExtProp' cannot be used on type 'ThisDerived1'}}
self.derivedExtFunc0() // expected-error {{instance member 'derivedExtFunc0' cannot be used on type 'ThisDerived1'}}
self.derivedExtStaticVar = 42 // expected-error {{instance member 'derivedExtStaticVar' cannot be used on type 'ThisDerived1'}}
self.derivedExtStaticProp = 42 // expected-error {{member 'derivedExtStaticProp' cannot be used on type 'ThisDerived1'}}
self.derivedExtStaticFunc0()
var ds1 : DerivedNestedStruct
var dc1 : DerivedNestedClass
var do1 : DerivedNestedUnion = .DerivedUnionX(42)
var dt1 : DerivedNestedTypealias
var ds2 = self.DerivedNestedStruct()
var dc2 = self.DerivedNestedClass()
var do2 = self.DerivedUnionX(24) // expected-error {{type 'ThisDerived1' has no member 'DerivedUnionX'}}
var do3 = self.DerivedNestedUnion.DerivedUnionX(24)
var dt2 = self.DerivedNestedTypealias()
var des1 : DerivedExtNestedStruct
var dec1 : DerivedExtNestedClass
var deo1 : DerivedExtNestedUnion = .DerivedExtUnionX(42)
var det1 : DerivedExtNestedTypealias
var des2 = self.DerivedExtNestedStruct()
var dec2 = self.DerivedExtNestedClass()
var deo2 = self.DerivedExtUnionX(24) // expected-error {{type 'ThisDerived1' has no member 'DerivedExtUnionX'}}
var deo3 = self.DerivedExtNestedUnion.DerivedExtUnionX(24)
var det2 = self.DerivedExtNestedTypealias()
self.Type // expected-error {{type 'ThisDerived1' has no member 'Type'}}
}
// FIXME: Partial application diagnostic is applied incorrectly for some
// test cases (https://github.com/apple/swift/issues/57572).
class func staticTestSuper1() {
super.baseInstanceVar = 42 // expected-error {{member 'baseInstanceVar' cannot be used on type 'ThisBase1'}}
super.baseProp = 42 // expected-error {{member 'baseProp' cannot be used on type 'ThisBase1'}}
super.baseFunc0() // expected-error {{instance member 'baseFunc0' cannot be used on type 'ThisBase1'}}
// expected-error@-1 {{cannot reference 'super' instance method with metatype base as function value}}
super.baseFunc0(ThisBase1())() // expected-error {{cannot reference 'super' instance method with metatype base as function value}}
super.baseFunc1(42) // expected-error {{instance member 'baseFunc1' cannot be used on type 'ThisBase1'}}
// expected-error@-1 {{cannot reference 'super' instance method with metatype base as function value}}
super.baseFunc1(ThisBase1())(42) // expected-error {{cannot reference 'super' instance method with metatype base as function value}}
super[0] = 42.0 // expected-error {{instance member 'subscript' cannot be used on type 'ThisBase1'}}
super.baseStaticVar = 42
super.baseStaticProp = 42
super.baseStaticFunc0()
super.baseExtProp = 42 // expected-error {{member 'baseExtProp' cannot be used on type 'ThisBase1'}}
super.baseExtFunc0() // expected-error {{instance member 'baseExtFunc0' cannot be used on type 'ThisBase1'}}
// expected-error@-1 {{cannot reference 'super' instance method with metatype base as function value}}
super.baseExtStaticVar = 42 // expected-error {{instance member 'baseExtStaticVar' cannot be used on type 'ThisBase1'}}
super.baseExtStaticProp = 42 // expected-error {{member 'baseExtStaticProp' cannot be used on type 'ThisBase1'}}
super.baseExtStaticFunc0()
var bs2 = super.BaseNestedStruct()
var bc2 = super.BaseNestedClass()
var bo2 = super.BaseUnionX(24) // expected-error {{type 'ThisBase1' has no member 'BaseUnionX'}}
var bo3 = super.BaseNestedUnion.BaseUnionX(24)
var bt2 = super.BaseNestedTypealias()
super.derivedInstanceVar = 42 // expected-error {{type 'ThisBase1' has no member 'derivedInstanceVar'}}
super.derivedProp = 42 // expected-error {{type 'ThisBase1' has no member 'derivedProp'}}
super.derivedFunc0() // expected-error {{type 'ThisBase1' has no member 'derivedFunc0'}}
super.derivedStaticVar = 42 // expected-error {{type 'ThisBase1' has no member 'derivedStaticVar'}}
super.derivedStaticProp = 42 // expected-error {{type 'ThisBase1' has no member 'derivedStaticProp'}}
super.derivedStaticFunc0() // expected-error {{type 'ThisBase1' has no member 'derivedStaticFunc0'}}
super.derivedExtProp = 42 // expected-error {{type 'ThisBase1' has no member 'derivedExtProp'}}
super.derivedExtFunc0() // expected-error {{type 'ThisBase1' has no member 'derivedExtFunc0'}}
super.derivedExtStaticVar = 42 // expected-error {{type 'ThisBase1' has no member 'derivedExtStaticVar'; did you mean 'baseExtStaticVar'?}}
super.derivedExtStaticProp = 42 // expected-error {{type 'ThisBase1' has no member 'derivedExtStaticProp'; did you mean 'baseExtStaticProp'?}}
super.derivedExtStaticFunc0() // expected-error {{type 'ThisBase1' has no member 'derivedExtStaticFunc0'; did you mean 'baseExtStaticFunc0'?}}
var ds2 = super.DerivedNestedStruct() // expected-error {{type 'ThisBase1' has no member 'DerivedNestedStruct'}}
var dc2 = super.DerivedNestedClass() // expected-error {{type 'ThisBase1' has no member 'DerivedNestedClass'}}
var do2 = super.DerivedUnionX(24) // expected-error {{type 'ThisBase1' has no member 'DerivedUnionX'}}
var do3 = super.DerivedNestedUnion.DerivedUnionX(24) // expected-error {{type 'ThisBase1' has no member 'DerivedNestedUnion'}}
var dt2 = super.DerivedNestedTypealias(42) // expected-error {{type 'ThisBase1' has no member 'DerivedNestedTypealias'}}
var des2 = super.DerivedExtNestedStruct() // expected-error {{type 'ThisBase1' has no member 'DerivedExtNestedStruct'; did you mean 'BaseExtNestedStruct'?}}
var dec2 = super.DerivedExtNestedClass() // expected-error {{type 'ThisBase1' has no member 'DerivedExtNestedClass'; did you mean 'BaseExtNestedClass'?}}
var deo2 = super.DerivedExtUnionX(24) // expected-error {{type 'ThisBase1' has no member 'DerivedExtUnionX'}}
var deo3 = super.DerivedExtNestedUnion.DerivedExtUnionX(24) // expected-error {{type 'ThisBase1' has no member 'DerivedExtNestedUnion'; did you mean 'BaseExtNestedUnion'?}}
var det2 = super.DerivedExtNestedTypealias(42) // expected-error {{type 'ThisBase1' has no member 'DerivedExtNestedTypealias'; did you mean 'BaseExtNestedTypealias'?}}
super.Type // expected-error {{type 'ThisBase1' has no member 'Type'}}
}
}
protocol Crawlable {}
extension Crawlable {
static func crawl() {}
}
struct GenericChameleon<U>: Crawlable {
static func chameleon() {}
func testStaticOnInstance(arg: GenericChameleon<Never>) {
arg.chameleon() // expected-error {{static member 'chameleon' cannot be used on instance of type 'GenericChameleon<Never>'}} {{5-8=GenericChameleon<Never>}}
arg.crawl() // expected-error {{static member 'crawl' cannot be used on instance of type 'GenericChameleon<Never>'}} {{5-8=GenericChameleon<Never>}}
}
}
extension ThisBase1 {
var baseExtProp : Int {
get {
return 42
}
set {}
}
func baseExtFunc0() {}
var baseExtStaticVar: Int // expected-error {{extensions must not contain stored properties}} // expected-note 2 {{'baseExtStaticVar' declared here}}
var baseExtStaticProp: Int { // expected-note 2 {{'baseExtStaticProp' declared here}}
get {
return 42
}
set {}
}
class func baseExtStaticFunc0() {} // expected-note {{'baseExtStaticFunc0' declared here}}
struct BaseExtNestedStruct {} // expected-note {{did you mean 'BaseExtNestedStruct'?}} // expected-note {{'BaseExtNestedStruct' declared here}}
class BaseExtNestedClass { // expected-note {{'BaseExtNestedClass' declared here}}
init() { }
}
enum BaseExtNestedUnion { // expected-note {{'BaseExtNestedUnion' declared here}}
case BaseExtUnionX(Int)
}
typealias BaseExtNestedTypealias = Int // expected-note {{did you mean 'BaseExtNestedTypealias'?}} // expected-note {{'BaseExtNestedTypealias' declared here}}
}
extension ThisDerived1 {
var derivedExtProp : Int {
get {
return 42
}
set {}
}
func derivedExtFunc0() {}
var derivedExtStaticVar: Int // expected-error {{extensions must not contain stored properties}}
var derivedExtStaticProp: Int {
get {
return 42
}
set {}
}
class func derivedExtStaticFunc0() {}
struct DerivedExtNestedStruct {}
class DerivedExtNestedClass {
init() { }
}
enum DerivedExtNestedUnion { // expected-note {{did you mean 'DerivedExtNestedUnion'?}}
case DerivedExtUnionX(Int)
}
typealias DerivedExtNestedTypealias = Int
}
// <rdar://problem/11554141>
func shadowbug() {
let Foo = 10
func g() {
struct S {
var x : Foo
typealias Foo = Int
}
}
_ = Foo
}
func scopebug() {
let Foo = 10
struct S {
typealias Foo = Int
}
_ = Foo
}
struct Ordering {
var x : Foo
typealias Foo = Int
}
// <rdar://problem/12202655>
class Outer {
class Inner {}
class MoreInner : Inner {}
}
func makeGenericStruct<S>(_ x: S) -> GenericStruct<S> {
return GenericStruct<S>()
}
struct GenericStruct<T> {}
// <rdar://problem/13952064>
extension Outer {
class ExtInner {}
}
// <rdar://problem/14149537>
func useProto<R : MyProto>(_ value: R) -> R.Element {
return value.get()
}
protocol MyProto {
associatedtype Element
func get() -> Element
}
// <rdar://problem/14488311>
struct DefaultArgumentFromExtension {
func g(_ x: @escaping (DefaultArgumentFromExtension) -> () -> () = f) {
let f = 42
var x2 = x
x2 = f // expected-error{{cannot assign value of type 'Int' to type '(DefaultArgumentFromExtension) -> () -> ()'}}
_ = x2
}
var x : (DefaultArgumentFromExtension) -> () -> () = f
}
extension DefaultArgumentFromExtension {
func f() {}
}
struct MyStruct {
var state : Bool
init() { state = true }
mutating func mod() {state = false}
// expected-note @+1 {{mark method 'mutating' to make 'self' mutable}} {{3-3=mutating }}
func foo() { mod() } // expected-error {{cannot use mutating member on immutable value: 'self' is immutable}}
}
// <rdar://problem/19935319> QoI: poor diagnostic initializing a variable with a non-class func
class Test19935319 {
let i = getFoo() // expected-error {{cannot use instance member 'getFoo' within property initializer; property initializers run before 'self' is available}}
func getFoo() -> Int {}
}
class Test19935319G<T> {
let i = getFoo()
// expected-error@-1 {{cannot use instance member 'getFoo' within property initializer; property initializers run before 'self' is available}}
func getFoo() -> Int { return 42 }
}
// <rdar://problem/27013358> Crash using instance member as default parameter
class rdar27013358 {
let defaultValue = 1
func returnTwo() -> Int {
return 2
}
init(defaulted value: Int = defaultValue) {} // expected-error {{cannot use instance member 'defaultValue' as a default parameter}}
init(another value: Int = returnTwo()) {} // expected-error {{cannot use instance member 'returnTwo' as a default parameter}}
}
class rdar27013358G<T> {
let defaultValue = 1
func returnTwo() -> Int {
return 2
}
init(defaulted value: Int = defaultValue) {} // expected-error {{cannot use instance member 'defaultValue' as a default parameter}}
init(another value: Int = returnTwo()) {} // expected-error {{cannot use instance member 'returnTwo' as a default parameter}}
}
// <rdar://problem/23904262> QoI: ivar default initializer cannot reference other default initialized ivars?
class r23904262 {
let x = 1
let y = x // expected-error {{cannot use instance member 'x' within property initializer; property initializers run before 'self' is available}}
}
// <rdar://problem/21677702> Static method reference in static var doesn't work
class r21677702 {
static func method(value: Int) -> Int { return value }
static let x = method(value: 123)
static let y = method(123) // expected-error {{missing argument label 'value:' in call}}
}
// <rdar://problem/31762378> lazy properties don't have to use "self." in their initializers.
class r16954496 {
func bar() {}
lazy var x: Array<() -> Void> = [bar]
}
// <rdar://problem/27413116> [Swift] Using static constant defined in enum when in switch statement doesn't compile
enum MyEnum {
case one
case two
case oneTwoThree
static let kMyConstant = "myConstant"
}
switch "someString" {
case MyEnum.kMyConstant: // this causes a compiler error
print("yay")
case MyEnum.self.kMyConstant: // this works fine
print("hmm")
default:
break
}
func foo() {
_ = MyEnum.One // expected-error {{enum type 'MyEnum' has no case 'One'; did you mean 'one'?}}{{14-17=one}}
_ = MyEnum.Two // expected-error {{enum type 'MyEnum' has no case 'Two'; did you mean 'two'?}}{{14-17=two}}
_ = MyEnum.OneTwoThree // expected-error {{enum type 'MyEnum' has no case 'OneTwoThree'; did you mean 'oneTwoThree'?}}{{14-25=oneTwoThree}}
}
enum MyGenericEnum<T> {
case one(T)
case oneTwo(T)
}
func foo1() {
_ = MyGenericEnum<Int>.One // expected-error {{enum type 'MyGenericEnum<Int>' has no case 'One'; did you mean 'one'?}}{{26-29=one}}
_ = MyGenericEnum<Int>.OneTwo // expected-error {{enum type 'MyGenericEnum<Int>' has no case 'OneTwo'; did you mean 'oneTwo'?}}{{26-32=oneTwo}}
}
// https://github.com/apple/swift/issues/46665
do {
let x = 5
if x < 0, let x = Optional(1) { } // expected-warning {{immutable value 'x' was never used; consider replacing with '_' or removing it}}
}
struct Person {
let name: String?
}
struct Company { // expected-note 2{{'Company' declared here}}
let owner: Person?
}
func test1() {
let example: Company? = Company(owner: Person(name: "Owner"))
if let person = aCompany.owner, // expected-error {{cannot find 'aCompany' in scope; did you mean 'Company'?}}
let aCompany = example {
_ = person
}
}
func test2() {
let example: Company? = Company(owner: Person(name: "Owner"))
guard let person = aCompany.owner, // expected-error {{cannot find 'aCompany' in scope; did you mean 'Company'?}}
let aCompany = example else { return }
}
func test3() {
var c: String? = "c" // expected-note {{'c' declared here}}
if let a = b = c, let b = c { // expected-error {{cannot find 'b' in scope; did you mean 'c'?}}
_ = b
}
}
// rdar://problem/22587551
class ShadowingGenericParameter<T> {
typealias T = Int
func foo (t : T) {}
}
ShadowingGenericParameter<String>().foo(t: "hi")
// rdar://problem/51266778
struct PatternBindingWithTwoVars1 { var x = 3, y = x }
// expected-error@-1 {{cannot use instance member 'x' within property initializer; property initializers run before 'self' is available}}
struct PatternBindingWithTwoVars2 { var x = y, y = 3 }
// expected-error@-1 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
struct PatternBindingWithTwoVars3 { var x = y, y = x }
// expected-error@-1 {{circular reference}}
// expected-note@-2 {{through reference here}}
// expected-note@-3 {{through reference here}}
// expected-note@-4 {{through reference here}}
// expected-note@-5 {{through reference here}}
// expected-note@-6 {{through reference here}}
// https://github.com/apple/swift/issues/51518
do {
let closure1 = { closure2() } // expected-error {{circular reference}} expected-note {{through reference here}} expected-note {{through reference here}}
let closure2 = { closure1() } // expected-note {{through reference here}} expected-note {{through reference here}} expected-note {{through reference here}}
}
func color(with value: Int) -> Int {
return value
}
func useColor() {
let color = color(with: 123)
_ = color
}