-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathattr_objc.swift
2657 lines (2072 loc) · 120 KB
/
attr_objc.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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// RUN: %empty-directory(%t)
// RUN: %{python} %S/Inputs/access-note-gen.py %s %t/attr_objc_access_note.swift %t/attr_objc_access_note.accessnotes
// Test with @objc attrs, without access notes
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference | %FileCheck %s
// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference > %t/attr_objc.ast
// RUN: %FileCheck -check-prefix CHECK-DUMP %s < %t/attr_objc.ast
// Test without @objc attrs, with access notes
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %t/attr_objc_access_note.swift -access-notes-path %t/attr_objc_access_note.accessnotes -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %t/attr_objc_access_note.swift -access-notes-path %t/attr_objc_access_note.accessnotes -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference | %FileCheck %t/attr_objc_access_note.swift
// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %t/attr_objc_access_note.swift -access-notes-path %t/attr_objc_access_note.accessnotes -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference > %t/attr_objc_access_note.ast
// RUN: %FileCheck -check-prefix CHECK-DUMP %t/attr_objc_access_note.swift < %t/attr_objc_access_note.ast
// Test with both @objc attrs and access notes
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -access-notes-path %t/attr_objc_access_note.accessnotes -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -access-notes-path %t/attr_objc_access_note.accessnotes -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference | %FileCheck %s
// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -access-notes-path %t/attr_objc_access_note.accessnotes -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference > %t/attr_objc_2.ast
// RUN: %FileCheck -check-prefix CHECK-DUMP %s < %t/attr_objc_2.ast
// REQUIRES: objc_interop
// HOW TO WORK ON THIS TEST
//
// This file is primarily used to test '@objc' in source files, but it is also
// processed to produce test files for access notes, which can annotate
// declarations with '@objc' based on a sidecar file. This processing produces
// a source file with most of the '@objc' annotations removed, plus an access
// note file which adds back the removed '@objc' annotations. The three files
// are then tested in various combinations.
//
// The processing step uses the following special commands, which must appear
// at the beginning of a line comment to be recognized:
//
// * `access-note-adjust @±offset` (where the offset is optional) modifies the
// rest of the line comment to:
//
// 1. Change expected errors to expected remarks
// 2. Adjust the line offsets of all expected diagnostics by the offset
// 3. Change the phrase "marked @objc" to "marked @objc by an access note"
// 4. Change all expected fix-its to "{{none}}"
//
// * `access-note-move @±offset {{name}}` (where the offset is optional) can
// only appear immediately after an `@objc` or `@objc(someName)` attribute.
// It removes the attribute from the source code, adds a corresponding
// access note for `name` to the access note file, and does the same
// processing to the rest of the line as access-note-adjust. Note that in this
// case, the offset is @+1, not @+0, unless something else is specified.
//
// Note that, in some cases, we need additional access notes to be added that
// don't directly correspond to any attribute in the source code (usually
// because one @objc attribute covers several declarations). When this happens,
// we write a commented-out @objc attribute and use the `access-note-move`
// command.
import Foundation
class PlainClass {}
struct PlainStruct {}
enum PlainEnum {}
protocol PlainProtocol {} // expected-note {{protocol 'PlainProtocol' declared here}}
enum ErrorEnum : Error {
case failed
}
@objc // access-note-move{{Class_ObjC1}}
class Class_ObjC1 {}
protocol Protocol_Class1 : class {} // expected-note {{protocol 'Protocol_Class1' declared here}}
protocol Protocol_Class2 : class {}
@objc // access-note-move{{Protocol_ObjC1}}
protocol Protocol_ObjC1 {}
@objc // access-note-move{{Protocol_ObjC2}}
protocol Protocol_ObjC2 {}
//===--- Subjects of @objc attribute.
@objc // expected-error{{'@objc' can only be applied to an extension of a class}}{{1-7=}}
extension PlainStruct { }
class FáncyName {}
@objc(FancyName)
extension FáncyName {}
@objc // access-note-move{{subject_globalVar}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}}
var subject_globalVar: Int
var subject_getterSetter: Int {
@objc // access-note-move{{getter:subject_getterSetter()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
get {
return 0
}
@objc // access-note-move{{setter:subject_getterSetter()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
set {
}
}
var subject_global_observingAccessorsVar1: Int = 0 {
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
willSet {
}
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
didSet {
}
}
class subject_getterSetter1 {
var instanceVar1: Int {
@objc // access-note-move{{getter:subject_getterSetter1.instanceVar1()}}
get { // access-note-adjust expected-error {{'@objc' getter for non-'@objc' property}}
return 0
}
}
var instanceVar2: Int {
get {
return 0
}
@objc // access-note-move{{setter:subject_getterSetter1.instanceVar2()}}
set { // access-note-adjust expected-error {{'@objc' setter for non-'@objc' property}}
}
}
var instanceVar3: Int {
@objc // access-note-move{{getter:subject_getterSetter1.instanceVar3()}}
get { // access-note-adjust expected-error {{'@objc' getter for non-'@objc' property}}
return 0
}
@objc // access-note-move{{setter:subject_getterSetter1.instanceVar3()}}
set { // access-note-adjust expected-error {{'@objc' setter for non-'@objc' property}}
}
}
var observingAccessorsVar1: Int = 0 {
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
willSet {
}
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
didSet {
}
}
}
class subject_staticVar1 {
@objc // access-note-move{{subject_staticVar1.staticVar1}}
class var staticVar1: Int = 42 // expected-error {{class stored properties not supported}}
@objc // access-note-move{{subject_staticVar1.staticVar2}}
class var staticVar2: Int { return 42 }
}
@objc // access-note-move{{subject_freeFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{1-7=}}
func subject_freeFunc() {
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
var subject_localVar: Int
// expected-warning@-1 {{variable 'subject_localVar' was never used; consider replacing with '_' or removing it}}
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
func subject_nestedFreeFunc() {
}
}
@objc // access-note-move{{subject_genericFunc(t:)}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{1-7=}}
func subject_genericFunc<T>(t: T) {
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
var subject_localVar: Int
// expected-warning@-1 {{variable 'subject_localVar' was never used; consider replacing with '_' or removing it}}
@objc // expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
func subject_instanceFunc() {}
}
func subject_funcParam(a: @objc Int) { // expected-error {{attribute can only be applied to declarations, not types}} {{1-1=@objc }} {{27-33=}}
}
@objc // access-note-move{{subject_struct}} expected-error {{'@objc' attribute cannot be applied to this declaration}} {{1-7=}}
struct subject_struct {
@objc // access-note-move{{subject_struct.subject_instanceVar}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
var subject_instanceVar: Int
@objc // access-note-move{{subject_struct.init()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
init() {}
@objc // access-note-move{{subject_struct.subject_instanceFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
func subject_instanceFunc() {}
}
@objc // access-note-move{{subject_genericStruct}} expected-error {{'@objc' attribute cannot be applied to this declaration}} {{1-7=}}
struct subject_genericStruct<T> {
@objc // access-note-move{{subject_genericStruct.subject_instanceVar}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
var subject_instanceVar: Int
@objc // access-note-move{{subject_genericStruct.init()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
init() {}
@objc // access-note-move{{subject_genericStruct.subject_instanceFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
func subject_instanceFunc() {}
}
@objc // access-note-move{{subject_class1}}
class subject_class1 { // no-error
@objc // access-note-move{{subject_class1.subject_instanceVar}}
var subject_instanceVar: Int // no-error
@objc // access-note-move{{subject_class1.init()}}
init() {} // no-error
@objc // access-note-move{{subject_class1.subject_instanceFunc()}}
func subject_instanceFunc() {} // no-error
}
@objc // access-note-move{{subject_class2}}
class subject_class2 : Protocol_Class1, PlainProtocol { // no-error
}
@objc // access-note-move{{subject_genericClass}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C}} {{1-7=}}
class subject_genericClass<T> {
@objc // access-note-move{{subject_genericClass.subject_instanceVar}}
var subject_instanceVar: Int // no-error
@objc // access-note-move{{subject_genericClass.init()}}
init() {} // no-error
@objc // access-note-move{{subject_genericClass.subject_instanceFunc()}}
func subject_instanceFunc() {} // no_error
}
@objc // access-note-move{{subject_genericClass2}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc'}} {{1-7=}}
class subject_genericClass2<T> : Class_ObjC1 {
@objc // access-note-move{{subject_genericClass2.subject_instanceVar}}
var subject_instanceVar: Int // no-error
@objc // access-note-move{{subject_genericClass2.init(foo:)}}
init(foo: Int) {} // no-error
@objc // access-note-move{{subject_genericClass2.subject_instanceFunc()}}
func subject_instanceFunc() {} // no_error
}
extension subject_genericClass where T : Hashable {
@objc // access-note-move{{subject_genericClass.prop}}
var prop: Int { return 0 } // access-note-adjust expected-error{{members of constrained extensions cannot be declared @objc}}
}
extension subject_genericClass {
@objc // access-note-move{{subject_genericClass.extProp}}
var extProp: Int { return 0 } // access-note-adjust expected-error{{extensions of generic classes cannot contain '@objc' members}}
@objc // access-note-move{{subject_genericClass.extFoo()}}
func extFoo() {} // access-note-adjust expected-error{{extensions of generic classes cannot contain '@objc' members}}
}
@objc // access-note-move{{subject_enum}}
enum subject_enum: Int {
@objc // access-note-move{{subject_enum.subject_enumElement1}} expected-error {{attribute has no effect; cases within an '@objc' enum are already exposed to Objective-C}} {{3-9=}}
case subject_enumElement1
@objc(subject_enumElement2) // access-note-move{{subject_enum.subject_enumElement2}}
case subject_enumElement2
// Fake for access notes: @objc(subject_enumElement3) // access-note-move@+2{{subject_enum.subject_enumElement4}}
@objc(subject_enumElement3) // access-note-move{{subject_enum.subject_enumElement3}} expected-error {{'@objc' enum case declaration defines multiple enum cases with the same Objective-C name}}{{3-31=}}
case subject_enumElement3, subject_enumElement4
// Becuase of the fake access-note-move above, we expect to see extra diagnostics when we run this test with both explicit @objc attributes *and* access notes:
// expected-remark@-2 * {{'@objc' enum case declaration defines multiple enum cases with the same Objective-C name}} expected-remark@-2 * {{access note for fancy tests adds attribute 'objc' to this enum case}} expected-note@-2 * {{add attribute explicitly to silence this warning}}
// Fake for access notes: @objc // access-note-move@+2{{subject_enum.subject_enumElement6}}
@objc // access-note-move{{subject_enum.subject_enumElement5}} expected-error {{attribute has no effect; cases within an '@objc' enum are already exposed to Objective-C}} {{3-9=}}
case subject_enumElement5, subject_enumElement6
// Becuase of the fake access-note-move above, we expect to see extra diagnostics when we run this test with both explicit @objc attributes *and* access notes:
// expected-remark@-2 * {{attribute has no effect; cases within an '@objc' enum are already exposed to Objective-C}} expected-remark@-2 * {{access note for fancy tests adds attribute 'objc' to this enum case}} expected-note@-2 * {{add attribute explicitly to silence this warning}}
@nonobjc // expected-error {{'@nonobjc' attribute cannot be applied to this declaration}}
case subject_enumElement7
@objc // access-note-move{{subject_enum.init()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
init() {}
@objc // access-note-move{{subject_enum.subject_instanceFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}} {{3-9=}}
func subject_instanceFunc() {}
}
enum subject_enum2 {
@objc(subject_enum2Element1) // access-note-move{{subject_enum2.subject_enumElement1}} expected-error{{'@objc' enum case is not allowed outside of an '@objc' enum}}{{3-32=}}
case subject_enumElement1
}
@objc // access-note-move{{subject_protocol1}}
protocol subject_protocol1 {
@objc // access-note-move{{subject_protocol1.subject_instanceVar}}
var subject_instanceVar: Int { get }
@objc // access-note-move{{subject_protocol1.subject_instanceFunc()}}
func subject_instanceFunc()
}
@objc // access-note-move{{subject_protocol2}} // no-error
protocol subject_protocol2 {}
// CHECK-LABEL: @objc protocol subject_protocol2 {
@objc // access-note-move{{subject_protocol3}} // no-error
protocol subject_protocol3 {}
// CHECK-LABEL: @objc protocol subject_protocol3 {
@objc // access-note-move{{subject_protocol4}}
protocol subject_protocol4 : PlainProtocol {} // expected-error {{@objc protocol 'subject_protocol4' cannot refine non-@objc protocol 'PlainProtocol'}}
@objc // access-note-move{{subject_protocol5}}
protocol subject_protocol5 : Protocol_Class1 {} // expected-error {{@objc protocol 'subject_protocol5' cannot refine non-@objc protocol 'Protocol_Class1'}}
@objc // access-note-move{{subject_protocol6}}
protocol subject_protocol6 : Protocol_ObjC1 {}
protocol subject_containerProtocol1 {
@objc // access-note-move{{subject_containerProtocol1.subject_instanceVar}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}}
var subject_instanceVar: Int { get }
@objc // access-note-move{{subject_containerProtocol1.subject_instanceFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}}
func subject_instanceFunc()
@objc // access-note-move{{subject_containerProtocol1.subject_staticFunc()}} expected-error {{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}}
static func subject_staticFunc()
}
@objc // access-note-move{{subject_containerObjCProtocol1}}
protocol subject_containerObjCProtocol1 {
func func_FunctionReturn1() -> PlainStruct
// expected-error@-1 {{method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
// expected-note@-3 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
func func_FunctionParam1(a: PlainStruct)
// expected-error@-1 {{method cannot be a member of an @objc protocol because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
// expected-note@-3 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
func func_Variadic(_: AnyObject...)
// expected-error @-1{{method cannot be a member of an @objc protocol because it has a variadic parameter}}
// expected-note @-2{{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
subscript(a: PlainStruct) -> Int { get }
// expected-error@-1 {{subscript cannot be a member of an @objc protocol because its type cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
// expected-note@-3 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
var varNonObjC1: PlainStruct { get }
// expected-error@-1 {{property cannot be a member of an @objc protocol because its type cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
// expected-note@-3 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
}
@objc // access-note-move{{subject_containerObjCProtocol2}}
protocol subject_containerObjCProtocol2 {
init(a: Int)
@objc // FIXME: Access notes can't distinguish between init(a:) overloads
init(a: Double)
func func1() -> Int
@objc // access-note-move{{subject_containerObjCProtocol2.func1_()}}
func func1_() -> Int
var instanceVar1: Int { get set }
@objc // access-note-move{{subject_containerObjCProtocol2.instanceVar1_}}
var instanceVar1_: Int { get set }
subscript(i: Int) -> Int { get set }
@objc // FIXME: Access notes can't distinguish between subscript(_:) overloads
subscript(i: String) -> Int { get set}
}
protocol nonObjCProtocol {
@objc // access-note-move{{nonObjCProtocol.objcRequirement()}} expected-error{{@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes}}
func objcRequirement()
}
func concreteContext1() {
@objc
class subject_inConcreteContext {}
}
class ConcreteContext2 {
@objc // access-note-move{{ConcreteContext2.subject_inConcreteContext}}
class subject_inConcreteContext {}
}
class ConcreteContext3 {
func dynamicSelf1() -> Self { return self }
@objc // access-note-move{{ConcreteContext3.dynamicSelf1_()}}
func dynamicSelf1_() -> Self { return self }
@objc // access-note-move{{ConcreteContext3.genericParams()}}
func genericParams<T: NSObject>() -> [T] { return [] } // access-note-adjust expected-error{{method cannot be marked @objc because it has generic parameters}}
@objc // access-note-move{{ConcreteContext3.returnObjCProtocolMetatype()}}
func returnObjCProtocolMetatype() -> NSCoding.Protocol { return NSCoding.self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
typealias AnotherNSCoding = NSCoding
typealias MetaNSCoding1 = NSCoding.Protocol
typealias MetaNSCoding2 = AnotherNSCoding.Protocol
@objc // access-note-move{{ConcreteContext3.returnObjCAliasProtocolMetatype1()}}
func returnObjCAliasProtocolMetatype1() -> AnotherNSCoding.Protocol { return NSCoding.self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
@objc // access-note-move{{ConcreteContext3.returnObjCAliasProtocolMetatype2()}}
func returnObjCAliasProtocolMetatype2() -> MetaNSCoding1 { return NSCoding.self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
@objc // access-note-move{{ConcreteContext3.returnObjCAliasProtocolMetatype3()}}
func returnObjCAliasProtocolMetatype3() -> MetaNSCoding2 { return NSCoding.self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
typealias Composition = NSCopying & NSCoding
@objc // access-note-move{{ConcreteContext3.returnCompositionMetatype1()}}
func returnCompositionMetatype1() -> Composition.Protocol { return Composition.self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
@objc // access-note-move{{ConcreteContext3.returnCompositionMetatype2()}}
func returnCompositionMetatype2() -> (NSCopying & NSCoding).Protocol { return (NSCopying & NSCoding).self } // access-note-adjust expected-error{{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
typealias NSCodingExistential = NSCoding.Type
@objc // access-note-move{{ConcreteContext3.inoutFunc(a:)}}
func inoutFunc(a: inout Int) {} // access-note-adjust expected-error{{method cannot be marked @objc because inout parameters cannot be represented in Objective-C}}
@objc // access-note-move{{ConcreteContext3.metatypeOfExistentialMetatypePram1(a:)}}
func metatypeOfExistentialMetatypePram1(a: NSCodingExistential.Protocol) {} // access-note-adjust expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
@objc // access-note-move{{ConcreteContext3.metatypeOfExistentialMetatypePram2(a:)}}
func metatypeOfExistentialMetatypePram2(a: NSCoding.Type.Protocol) {} // access-note-adjust expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
}
func genericContext1<T>(_: T) {
@objc // expected-error {{generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C}} {{3-9=}}
class subject_inGenericContext {} // expected-error {{type 'subject_inGenericContext' cannot be nested in generic function 'genericContext1'}}
@objc // expected-error {{generic subclasses of '@objc' classes cannot have an explicit '@objc'}} {{3-9=}}
class subject_inGenericContext2 : Class_ObjC1 {} // expected-error {{type 'subject_inGenericContext2' cannot be nested in generic function 'genericContext1'}}
class subject_constructor_inGenericContext { // expected-error {{type 'subject_constructor_inGenericContext' cannot be nested in generic function 'genericContext1'}}
@objc
init() {} // no-error
}
class subject_var_inGenericContext { // expected-error {{type 'subject_var_inGenericContext' cannot be nested in generic function 'genericContext1'}}
@objc
var subject_instanceVar: Int = 0 // no-error
}
class subject_func_inGenericContext { // expected-error {{type 'subject_func_inGenericContext' cannot be nested in generic function 'genericContext1'}}
@objc
func f() {} // no-error
}
}
class GenericContext2<T> {
@objc // access-note-move{{GenericContext2.subject_inGenericContext}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C}} {{3-9=}}
class subject_inGenericContext {}
@objc // access-note-move{{GenericContext2.subject_inGenericContext2}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc'}} {{3-9=}}
class subject_inGenericContext2 : Class_ObjC1 {}
@objc // access-note-move{{GenericContext2.f()}}
func f() {} // no-error
}
class GenericContext3<T> {
class MoreNested {
@objc // access-note-move{{GenericContext3.MoreNested.subject_inGenericContext}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C}} {{5-11=}}
class subject_inGenericContext {}
@objc // access-note-move{{GenericContext3.MoreNested.subject_inGenericContext2}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc'}} {{5-11=}}
class subject_inGenericContext2 : Class_ObjC1 {}
@objc // access-note-move{{GenericContext3.MoreNested.f()}}
func f() {} // no-error
}
}
class GenericContext4<T> {
@objc // access-note-move{{GenericContext4.foo()}}
func foo() where T: Hashable { } // access-note-adjust expected-error {{instance method cannot be marked @objc because it has a 'where' clause}}
}
@objc // access-note-move{{ConcreteSubclassOfGeneric}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C}} {{1-7=}}
class ConcreteSubclassOfGeneric : GenericContext3<Int> {}
extension ConcreteSubclassOfGeneric {
@objc // access-note-move{{ConcreteSubclassOfGeneric.foo()}}
func foo() {} // okay
}
@objc // access-note-move{{ConcreteSubclassOfGeneric2}} expected-error{{generic subclasses of '@objc' classes cannot have an explicit '@objc'}} {{1-7=}}
class ConcreteSubclassOfGeneric2 : subject_genericClass2<Int> {}
extension ConcreteSubclassOfGeneric2 {
@objc // access-note-move{{ConcreteSubclassOfGeneric2.foo()}}
func foo() {} // okay
}
@objc(CustomNameForSubclassOfGeneric) // access-note-move{{ConcreteSubclassOfGeneric3}} no-error
class ConcreteSubclassOfGeneric3 : GenericContext3<Int> {}
extension ConcreteSubclassOfGeneric3 {
@objc // access-note-move{{ConcreteSubclassOfGeneric3.foo()}}
func foo() {} // okay
}
class subject_subscriptIndexed1 {
@objc // access-note-move{{subject_subscriptIndexed1.subscript(_:)}}
subscript(a: Int) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptIndexed2 {
@objc // access-note-move{{subject_subscriptIndexed2.subscript(_:)}}
subscript(a: Int8) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptIndexed3 {
@objc // access-note-move{{subject_subscriptIndexed3.subscript(_:)}}
subscript(a: UInt8) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed1 {
@objc // access-note-move{{subject_subscriptKeyed1.subscript(_:)}}
subscript(a: String) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed2 {
@objc // access-note-move{{subject_subscriptKeyed2.subscript(_:)}}
subscript(a: Class_ObjC1) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed3 {
@objc // access-note-move{{subject_subscriptKeyed3.subscript(_:)}}
subscript(a: Class_ObjC1.Type) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed4 {
@objc // access-note-move{{subject_subscriptKeyed4.subscript(_:)}}
subscript(a: Protocol_ObjC1) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed5 {
@objc // access-note-move{{subject_subscriptKeyed5.subscript(_:)}}
subscript(a: Protocol_ObjC1.Type) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed6 {
@objc // access-note-move{{subject_subscriptKeyed6.subscript(_:)}}
subscript(a: Protocol_ObjC1 & Protocol_ObjC2) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptKeyed7 {
@objc // access-note-move{{subject_subscriptKeyed7.subscript(_:)}}
subscript(a: (Protocol_ObjC1 & Protocol_ObjC2).Type) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptBridgedFloat {
@objc // access-note-move{{subject_subscriptBridgedFloat.subscript(_:)}}
subscript(a: Float32) -> Int {
get { return 0 }
}
}
class subject_subscriptGeneric<T> {
@objc // access-note-move{{subject_subscriptGeneric.subscript(_:)}}
subscript(a: Int) -> Int { // no-error
get { return 0 }
}
}
class subject_subscriptInvalid1 {
@objc // access-note-move{{subject_subscriptInvalid1.subscript(_:)}}
class subscript(_ i: Int) -> AnyObject? { // access-note-adjust expected-error {{class subscript cannot be marked @objc}}
return nil
}
}
class subject_subscriptInvalid2 {
@objc // access-note-move{{subject_subscriptInvalid2.subscript(_:)}}
subscript(a: PlainClass) -> Int {
// access-note-adjust expected-error@-1 {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-2 {{classes not annotated with @objc cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid3 {
@objc // access-note-move{{subject_subscriptInvalid3.subscript(_:)}}
subscript(a: PlainClass.Type) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid4 {
@objc // access-note-move{{subject_subscriptInvalid4.subscript(_:)}}
subscript(a: PlainStruct) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{Swift structs cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid5 {
@objc // access-note-move{{subject_subscriptInvalid5.subscript(_:)}}
subscript(a: PlainEnum) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{enums cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid6 {
@objc // access-note-move{{subject_subscriptInvalid6.subscript(_:)}}
subscript(a: PlainProtocol) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{protocol-constrained type containing protocol 'PlainProtocol' cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid7 {
@objc // access-note-move{{subject_subscriptInvalid7.subscript(_:)}}
subscript(a: Protocol_Class1) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{protocol-constrained type containing protocol 'Protocol_Class1' cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_subscriptInvalid8 {
@objc // access-note-move{{subject_subscriptInvalid8.subscript(_:)}}
subscript(a: Protocol_Class1 & Protocol_Class2) -> Int { // access-note-adjust expected-error {{subscript cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{protocol-constrained type containing protocol 'Protocol_Class1' cannot be represented in Objective-C}}
get { return 0 }
}
}
class subject_propertyInvalid1 {
@objc // access-note-move{{subject_propertyInvalid1.plainStruct}}
let plainStruct = PlainStruct() // access-note-adjust expected-error {{property cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-1{{Swift structs cannot be represented in Objective-C}}
}
//===--- Tests for @objc inference.
@objc // access-note-move{{infer_instanceFunc1}}
class infer_instanceFunc1 {
// CHECK-LABEL: @objc class infer_instanceFunc1 {
func func1() {}
// CHECK-LABEL: @objc func func1() {
@objc // access-note-move{{infer_instanceFunc1.func1_()}}
func func1_() {} // no-error
func func2(a: Int) {}
// CHECK-LABEL: @objc func func2(a: Int) {
@objc // access-note-move{{infer_instanceFunc1.func2_(a:)}}
func func2_(a: Int) {} // no-error
func func3(a: Int) -> Int {}
// CHECK-LABEL: @objc func func3(a: Int) -> Int {
@objc // access-note-move{{infer_instanceFunc1.func3_(a:)}}
func func3_(a: Int) -> Int {} // no-error
func func4(a: Int, b: Double) {}
// CHECK-LABEL: @objc func func4(a: Int, b: Double) {
@objc // access-note-move{{infer_instanceFunc1.func4_(a:b:)}}
func func4_(a: Int, b: Double) {} // no-error
func func5(a: String) {}
// CHECK-LABEL: @objc func func5(a: String) {
@objc // access-note-move{{infer_instanceFunc1.func5_(a:)}}
func func5_(a: String) {} // no-error
func func6() -> String {}
// CHECK-LABEL: @objc func func6() -> String {
@objc // access-note-move{{infer_instanceFunc1.func6_()}}
func func6_() -> String {} // no-error
func func7(a: PlainClass) {}
// CHECK-LABEL: {{^}} func func7(a: PlainClass) {
@objc // access-note-move{{infer_instanceFunc1.func7_(a:)}}
func func7_(a: PlainClass) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{classes not annotated with @objc cannot be represented in Objective-C}}
func func7m(a: PlainClass.Type) {}
// CHECK-LABEL: {{^}} func func7m(a: PlainClass.Type) {
@objc // access-note-move{{infer_instanceFunc1.func7m_(a:)}}
func func7m_(a: PlainClass.Type) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
func func8() -> PlainClass {}
// CHECK-LABEL: {{^}} func func8() -> PlainClass {
@objc // access-note-move{{infer_instanceFunc1.func8_()}}
func func8_() -> PlainClass {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
// expected-note@-2 {{classes not annotated with @objc cannot be represented in Objective-C}}
func func8m() -> PlainClass.Type {}
// CHECK-LABEL: {{^}} func func8m() -> PlainClass.Type {
@objc // access-note-move{{infer_instanceFunc1.func8m_()}}
func func8m_() -> PlainClass.Type {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
func func9(a: PlainStruct) {}
// CHECK-LABEL: {{^}} func func9(a: PlainStruct) {
@objc // access-note-move{{infer_instanceFunc1.func9_(a:)}}
func func9_(a: PlainStruct) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
func func10() -> PlainStruct {}
// CHECK-LABEL: {{^}} func func10() -> PlainStruct {
@objc // access-note-move{{infer_instanceFunc1.func10_()}}
func func10_() -> PlainStruct {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
func func11(a: PlainEnum) {}
// CHECK-LABEL: {{^}} func func11(a: PlainEnum) {
@objc // access-note-move{{infer_instanceFunc1.func11_(a:)}}
func func11_(a: PlainEnum) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{non-'@objc' enums cannot be represented in Objective-C}}
func func12(a: PlainProtocol) {}
// CHECK-LABEL: {{^}} func func12(a: PlainProtocol) {
@objc // access-note-move{{infer_instanceFunc1.func12_(a:)}}
func func12_(a: PlainProtocol) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{protocol-constrained type containing protocol 'PlainProtocol' cannot be represented in Objective-C}}
func func13(a: Class_ObjC1) {}
// CHECK-LABEL: @objc func func13(a: Class_ObjC1) {
@objc // access-note-move{{infer_instanceFunc1.func13_(a:)}}
func func13_(a: Class_ObjC1) {} // no-error
func func14(a: Protocol_Class1) {}
// CHECK-LABEL: {{^}} func func14(a: Protocol_Class1) {
@objc // access-note-move{{infer_instanceFunc1.func14_(a:)}}
func func14_(a: Protocol_Class1) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{protocol-constrained type containing protocol 'Protocol_Class1' cannot be represented in Objective-C}}
func func15(a: Protocol_ObjC1) {}
// CHECK-LABEL: @objc func func15(a: Protocol_ObjC1) {
@objc // access-note-move{{infer_instanceFunc1.func15_(a:)}}
func func15_(a: Protocol_ObjC1) {} // no-error
func func16(a: AnyObject) {}
// CHECK-LABEL: @objc func func16(a: AnyObject) {
@objc // access-note-move{{infer_instanceFunc1.func16_(a:)}}
func func16_(a: AnyObject) {} // no-error
func func17(a: @escaping () -> ()) {}
// CHECK-LABEL: {{^}} @objc func func17(a: @escaping () -> ()) {
@objc // access-note-move{{infer_instanceFunc1.func17_(a:)}}
func func17_(a: @escaping () -> ()) {}
func func18(a: @escaping (Int) -> (), b: Int) {}
// CHECK-LABEL: {{^}} @objc func func18(a: @escaping (Int) -> (), b: Int)
@objc // access-note-move{{infer_instanceFunc1.func18_(a:b:)}}
func func18_(a: @escaping (Int) -> (), b: Int) {}
func func19(a: @escaping (String) -> (), b: Int) {}
// CHECK-LABEL: {{^}} @objc func func19(a: @escaping (String) -> (), b: Int) {
@objc // access-note-move{{infer_instanceFunc1.func19_(a:b:)}}
func func19_(a: @escaping (String) -> (), b: Int) {}
func func_FunctionReturn1() -> () -> () {}
// CHECK-LABEL: {{^}} @objc func func_FunctionReturn1() -> () -> () {
@objc // access-note-move{{infer_instanceFunc1.func_FunctionReturn1_()}}
func func_FunctionReturn1_() -> () -> () {}
func func_FunctionReturn2() -> (Int) -> () {}
// CHECK-LABEL: {{^}} @objc func func_FunctionReturn2() -> (Int) -> () {
@objc // access-note-move{{infer_instanceFunc1.func_FunctionReturn2_()}}
func func_FunctionReturn2_() -> (Int) -> () {}
func func_FunctionReturn3() -> () -> Int {}
// CHECK-LABEL: {{^}} @objc func func_FunctionReturn3() -> () -> Int {
@objc // access-note-move{{infer_instanceFunc1.func_FunctionReturn3_()}}
func func_FunctionReturn3_() -> () -> Int {}
func func_FunctionReturn4() -> (String) -> () {}
// CHECK-LABEL: {{^}} @objc func func_FunctionReturn4() -> (String) -> () {
@objc // access-note-move{{infer_instanceFunc1.func_FunctionReturn4_()}}
func func_FunctionReturn4_() -> (String) -> () {}
func func_FunctionReturn5() -> () -> String {}
// CHECK-LABEL: {{^}} @objc func func_FunctionReturn5() -> () -> String {
@objc // access-note-move{{infer_instanceFunc1.func_FunctionReturn5_()}}
func func_FunctionReturn5_() -> () -> String {}
func func_ZeroParams1() {}
// CHECK-LABEL: @objc func func_ZeroParams1() {
@objc // access-note-move{{infer_instanceFunc1.func_ZeroParams1a()}}
func func_ZeroParams1a() {} // no-error
func func_OneParam1(a: Int) {}
// CHECK-LABEL: @objc func func_OneParam1(a: Int) {
@objc // access-note-move{{infer_instanceFunc1.func_OneParam1a(a:)}}
func func_OneParam1a(a: Int) {} // no-error
func func_TupleStyle1(a: Int, b: Int) {}
// CHECK-LABEL: {{^}} @objc func func_TupleStyle1(a: Int, b: Int) {
@objc // access-note-move{{infer_instanceFunc1.func_TupleStyle1a(a:b:)}}
func func_TupleStyle1a(a: Int, b: Int) {}
func func_TupleStyle2(a: Int, b: Int, c: Int) {}
// CHECK-LABEL: {{^}} @objc func func_TupleStyle2(a: Int, b: Int, c: Int) {
@objc // access-note-move{{infer_instanceFunc1.func_TupleStyle2a(a:b:c:)}}
func func_TupleStyle2a(a: Int, b: Int, c: Int) {}
// Check that we produce diagnostics for every parameter and return type.
@objc // access-note-move{{infer_instanceFunc1.func_MultipleDiags(a:b:)}}
func func_MultipleDiags(a: PlainStruct, b: PlainEnum) -> Any {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter 1 cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
// access-note-adjust expected-error@-3 {{method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C}}
// expected-note@-4 {{non-'@objc' enums cannot be represented in Objective-C}}
@objc // access-note-move{{infer_instanceFunc1.func_UnnamedParam1(_:)}}
func func_UnnamedParam1(_: Int) {} // no-error
@objc // access-note-move{{infer_instanceFunc1.func_UnnamedParam2(_:)}}
func func_UnnamedParam2(_: PlainStruct) {}
// access-note-adjust expected-error@-1 {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
@objc // access-note-move{{infer_instanceFunc1.func_varParam1(a:)}}
func func_varParam1(a: AnyObject) {
var a = a
let b = a; a = b
}
func func_varParam2(a: AnyObject) {
var a = a
let b = a; a = b
}
// CHECK-LABEL: @objc func func_varParam2(a: AnyObject) {
}
@objc // access-note-move{{infer_constructor1}}
class infer_constructor1 {
// CHECK-LABEL: @objc class infer_constructor1
init() {}
// CHECK: @objc init()
init(a: Int) {}
// CHECK: @objc init(a: Int)
init(a: PlainStruct) {}
// CHECK: {{^}} init(a: PlainStruct)
init(malice: ()) {}
// CHECK: @objc init(malice: ())
init(forMurder _: ()) {}
// CHECK: @objc init(forMurder _: ())
}
@objc // access-note-move{{infer_destructor1}}
class infer_destructor1 {
// CHECK-LABEL: @objc class infer_destructor1
deinit {}
// CHECK: @objc deinit
}
// @!objc
class infer_destructor2 {
// CHECK-LABEL: {{^}}class infer_destructor2
deinit {}
// CHECK: @objc deinit
}
@objc // access-note-move{{infer_instanceVar1}}
class infer_instanceVar1 {
// CHECK-LABEL: @objc class infer_instanceVar1 {
init() {}
var instanceVar1: Int
// CHECK: @objc var instanceVar1: Int
var (instanceVar2, instanceVar3): (Int, PlainProtocol)
// CHECK: @objc var instanceVar2: Int
// CHECK: {{^}} var instanceVar3: PlainProtocol
@objc // access-note-move{{infer_instanceVar1.instanceVar1_}}
var (instanceVar1_, instanceVar2_): (Int, PlainProtocol)
// access-note-adjust expected-error@-1 {{property cannot be marked @objc because its type cannot be represented in Objective-C}}
// expected-note@-2 {{protocol-constrained type containing protocol 'PlainProtocol' cannot be represented in Objective-C}}
// Fake for access notes: @objc // access-note-move@-3{{infer_instanceVar1.instanceVar2_}}
var intstanceVar4: Int {
// CHECK: @objc var intstanceVar4: Int {
get {}
// CHECK-NEXT: @objc get {}
}
var intstanceVar5: Int {
// CHECK: @objc var intstanceVar5: Int {
get {}
// CHECK-NEXT: @objc get {}
set {}
// CHECK-NEXT: @objc set {}
}
@objc // access-note-move{{infer_instanceVar1.instanceVar5_}}
var instanceVar5_: Int {
// CHECK: @objc var instanceVar5_: Int {
get {}
// CHECK-NEXT: @objc get {}
set {}
// CHECK-NEXT: @objc set {}
}
var observingAccessorsVar1: Int {
// CHECK: @_hasStorage @objc var observingAccessorsVar1: Int {
willSet {}
// CHECK-NEXT: {{^}} @objc get {
// CHECK-NEXT: return
// CHECK-NEXT: }
didSet {}
// CHECK-NEXT: {{^}} @objc set {
}
@objc // access-note-move{{infer_instanceVar1.observingAccessorsVar1_}}
var observingAccessorsVar1_: Int {
// CHECK: {{^}} @objc @_hasStorage var observingAccessorsVar1_: Int {
willSet {}
// CHECK-NEXT: {{^}} @objc get {
// CHECK-NEXT: return
// CHECK-NEXT: }
didSet {}
// CHECK-NEXT: {{^}} @objc set {
}
var var_Int: Int
// CHECK-LABEL: @objc var var_Int: Int
var var_Bool: Bool
// CHECK-LABEL: @objc var var_Bool: Bool
var var_CBool: CBool
// CHECK-LABEL: @objc var var_CBool: CBool