| 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | #if !__has_feature(objc_class_property) |
| 4 | #error does not support class property |
| 5 | #endif |
| 6 | |
| 7 | @interface Root |
| 8 | -(id) alloc; |
| 9 | -(id) init; |
| 10 | @end |
| 11 | |
| 12 | @interface A : Root { |
| 13 | int x; |
| 14 | int z; |
| 15 | } |
| 16 | @property int x; |
| 17 | @property int y; |
| 18 | @property int z; |
| 19 | @property(readonly) int ro, ro2; |
| 20 | @property (class) int c; |
| 21 | @property (class) int c2; // expected-note {{property declared here}} \ |
| 22 | // expected-note {{property declared here}} |
| 23 | @property (class) int x; |
| 24 | @property (class, setter=customSet:) int customSetterProperty; |
| 25 | @property (class, getter=customGet) int customGetterProperty; |
| 26 | @end |
| 27 | |
| 28 | @implementation A // expected-warning {{class property 'c2' requires method 'c2' to be defined}} \ |
| 29 | // expected-warning {{class property 'c2' requires method 'setC2:' to be defined}} |
| 30 | @dynamic x; // refers to the instance property |
| 31 | @dynamic (class) x; // refers to the class property |
| 32 | @synthesize z, c2; // expected-error {{@synthesize not allowed on a class property 'c2'}} |
| 33 | @dynamic c; // refers to the class property |
| 34 | @dynamic customSetterProperty; |
| 35 | @dynamic customGetterProperty; |
| 36 | @end |
| 37 | |
| 38 | int test() { |
| 39 | A *a = [[A alloc] init]; |
| 40 | a.c; // expected-error {{property 'c' is a class property; did you mean to access it with class 'A'}} |
| 41 | return a.x + A.c; |
| 42 | } |
| 43 | |
| 44 | void customSelectors() { |
| 45 | A.customSetterProperty = 1; |
| 46 | (void)A.customGetterProperty; |
| 47 | } |
| 48 | |
| 49 | void message_id(id me) { |
| 50 | [me y]; |
| 51 | } |
| 52 | |
| 53 | void message_class(Class me) { |
| 54 | [me c2]; |
| 55 | } |
| 56 | |
| 57 | @interface NSObject |
| 58 | @end |
| 59 | |
| 60 | @interface MyClass : NSObject |
| 61 | @property(class, readonly) int classProp; // expected-note {{property declared here}} |
| 62 | @end |
| 63 | |
| 64 | @implementation MyClass // expected-warning {{class property 'classProp' requires method 'classProp' to be defined}} |
| 65 | - (int)classProp { // Oops, mistakenly made this an instance method. |
| 66 | return 8; |
| 67 | } |
| 68 | @end |
| 69 | |