Rafael Espindola | 14f9889 | 2013-09-27 20:21:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -disable-objc-default-synthesize-properties -Wno-objc-root-class %s |
Fariborz Jahanian | 6669db9 | 2008-11-25 17:56:43 +0000 | [diff] [blame] | 2 | |
| 3 | @interface Object |
Steve Naroff | 6b9dfd4 | 2009-03-04 15:11:40 +0000 | [diff] [blame] | 4 | + (id)new; |
Fariborz Jahanian | 6669db9 | 2008-11-25 17:56:43 +0000 | [diff] [blame] | 5 | @end |
| 6 | |
| 7 | @interface ReadOnly : Object |
| 8 | { |
| 9 | int _object; |
| 10 | int _Anotherobject; |
| 11 | } |
| 12 | @property(readonly) int object; |
| 13 | @property(readonly) int Anotherobject; |
| 14 | @end |
| 15 | |
| 16 | @interface ReadOnly () |
| 17 | @property(readwrite) int object; |
| 18 | @property(readwrite, setter = myAnotherobjectSetter:) int Anotherobject; |
| 19 | @end |
| 20 | |
| 21 | @implementation ReadOnly |
| 22 | @synthesize object = _object; |
| 23 | @synthesize Anotherobject = _Anotherobject; |
| 24 | - (void) myAnotherobjectSetter : (int)val { |
| 25 | _Anotherobject = val; |
| 26 | } |
Fariborz Jahanian | 7ca8b06 | 2009-11-11 22:40:11 +0000 | [diff] [blame] | 27 | - (int) Anotherobject { return _Anotherobject; } |
Fariborz Jahanian | 6669db9 | 2008-11-25 17:56:43 +0000 | [diff] [blame] | 28 | @end |
| 29 | |
| 30 | int main(int argc, char **argv) { |
| 31 | ReadOnly *test = [ReadOnly new]; |
| 32 | test.object = 12345; |
| 33 | test.Anotherobject = 200; |
| 34 | return test.object - 12345 + test.Anotherobject - 200; |
| 35 | } |
| 36 | |
Daniel Dunbar | 84efc04 | 2009-01-09 01:04:21 +0000 | [diff] [blame] | 37 | /// |
| 38 | |
| 39 | @interface I0 |
Fariborz Jahanian | b860739 | 2011-08-27 21:55:47 +0000 | [diff] [blame] | 40 | @property(readonly) int p0; // expected-note {{property declared here}} |
Daniel Dunbar | 84efc04 | 2009-01-09 01:04:21 +0000 | [diff] [blame] | 41 | @end |
| 42 | |
| 43 | @interface I0 (Cat0) |
| 44 | @end |
| 45 | |
| 46 | @interface I0 (Cat1) |
| 47 | @end |
| 48 | |
Fariborz Jahanian | b860739 | 2011-08-27 21:55:47 +0000 | [diff] [blame] | 49 | @implementation I0 // expected-warning {{property 'p0' requires method 'p0' to be define}} |
Daniel Dunbar | 84efc04 | 2009-01-09 01:04:21 +0000 | [diff] [blame] | 50 | - (void) foo { |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 51 | self.p0 = 0; // expected-error {{assignment to readonly property}} |
Daniel Dunbar | 84efc04 | 2009-01-09 01:04:21 +0000 | [diff] [blame] | 52 | } |
| 53 | @end |