[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaObjC / method-direct-properties.m
blob26d13010551f7ab2b91b19c60b52d1944fc2593c
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wselector-type-mismatch %s
3 @protocol ProtoDirectFail
4 @property(nonatomic, direct) int protoProperty; // expected-error {{'objc_direct' attribute cannot be applied to properties declared in an Objective-C protocol}}
5 @end
7 __attribute__((objc_root_class))
8 @interface Root
9 @property(nonatomic, direct) int propertyWithNonDirectGetter; // expected-note {{previous declaration is here}}
10 - (int)propertyWithNonDirectGetter;
11 - (int)propertyWithNonDirectGetter2;
12 - (int)propertyWithNonDirectGetterInParent;
13 - (int)propertyWithNonDirectGetterInParent2;
15 @property(nonatomic, readonly, direct) int getDirect_setDynamic;       // expected-note {{previous declaration is here}}
16 @property(nonatomic, readonly, direct) int getDirect_setDirect;        // expected-note {{previous declaration is here}}
17 @property(nonatomic, readonly, direct) int getDirect_setDirectMembers; // expected-note {{previous declaration is here}}
19 @property(nonatomic, readonly) int getDynamic_setDirect;
20 @property(nonatomic, readonly) int getDynamic_setDirectMembers;
22 @property(nonatomic, readonly) int dynamicProperty;
23 @property(nonatomic, readonly) int synthDynamicProperty;
25 @property(nonatomic, readonly, direct) int directProperty;      // expected-note {{previous declaration is here}}
26 @property(nonatomic, readonly, direct) int synthDirectProperty; // expected-note {{previous declaration is here}}
27 @end
29 __attribute__((objc_direct_members))
30 @interface
31 Root()
32 @property(nonatomic) int propertyWithNonDirectGetter2; // expected-note {{previous declaration is here}}
34 @property(nonatomic, readwrite) int getDirect_setDirectMembers;  // expected-note {{previous declaration is here}}
35 @property(nonatomic, readwrite) int getDynamic_setDirectMembers; // expected-note {{previous declaration is here}}
36 @end
38 @interface Root ()
39 @property(nonatomic, readwrite) int getDirect_setDynamic;
40 @property(nonatomic, readwrite, direct) int getDirect_setDirect; // expected-note {{previous declaration is here}}
42 @property(nonatomic, readwrite, direct) int getDynamic_setDirect; // expected-note {{previous declaration is here}}
43 @end
45 @interface Sub : Root
46 @property(nonatomic, direct) int propertyWithNonDirectGetterInParent; // expected-note {{previous declaration is here}}
48 - (int)propertyWithNonDirectGetter;          // no error: legal override
49 - (int)propertyWithNonDirectGetter2;         // no error: legal override
50 - (int)propertyWithNonDirectGetterInParent;  // no error: legal override
51 - (int)propertyWithNonDirectGetterInParent2; // no error: legal override
53 @end
55 __attribute__((objc_direct_members))
56 @interface Sub ()
57 @property(nonatomic) int propertyWithNonDirectGetterInParent2; // expected-note {{previous declaration is here}}
58 @end
60 // make sure that the `directness` of methods stuck,
61 // by observing errors trying to override the setter
62 @interface SubWitness : Sub
64 - (int)setPropertyWithNonDirectGetter:(int)value;          // expected-error {{cannot override a method that is declared direct by a superclass}}
65 - (int)setPropertyWithNonDirectGetter2:(int)value;         // expected-error {{cannot override a method that is declared direct by a superclass}}
66 - (int)setPropertyWithNonDirectGetterInParent:(int)value;  // expected-error {{cannot override a method that is declared direct by a superclass}}
67 - (int)setPropertyWithNonDirectGetterInParent2:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}}
69 - (int)getDirect_setDynamic; // expected-error {{cannot override a method that is declared direct by a superclass}}
70 - (int)setGetDirect_setDynamic:(int)value;
71 - (int)getDirect_setDirect;                      // expected-error {{cannot override a method that is declared direct by a superclass}}
72 - (int)setGetDirect_setDirect:(int)value;        // expected-error {{cannot override a method that is declared direct by a superclass}}
73 - (int)getDirect_setDirectMembers;               // expected-error {{cannot override a method that is declared direct by a superclass}}
74 - (int)setGetDirect_setDirectMembers:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}}
76 - (int)getDynamic_setDirect;
77 - (int)setGetDynamic_setDirect:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}}
78 - (int)getDynamic_setDirectMembers;
79 - (int)setGetDynamic_setDirectMembers:(int)value; // expected-error {{cannot override a method that is declared direct by a superclass}}
80 @end
82 __attribute__((objc_direct_members))
83 @implementation Root
84 - (int)propertyWithNonDirectGetter {
85   return 42;
87 - (int)propertyWithNonDirectGetter2 {
88   return 42;
90 - (int)propertyWithNonDirectGetterInParent {
91   return 42;
93 - (int)propertyWithNonDirectGetterInParent2 {
94   return 42;
97 - (int)dynamicProperty {
98   return 42;
100 - (int)directProperty {
101   return 42;
103 @end
105 @implementation Sub
106 - (int)propertyWithNonDirectGetter {
107   return 42;
109 - (int)propertyWithNonDirectGetter2 {
110   return 42;
113 - (int)dynamicProperty {
114   return 42;
116 - (int)synthDynamicProperty {
117   return 42;
120 - (int)directProperty { // expected-error {{cannot override a method that is declared direct by a superclass}}
121   return 42;
123 - (int)synthDirectProperty { // expected-error {{cannot override a method that is declared direct by a superclass}}
124   return 42;
126 @end