blob: 0e8c3fcd85df3edad531584ce16ed8f665ab21d3 [file] [log] [blame]
Rafael Espindola14f98892013-09-27 20:21:48 +00001// RUN: %clang_cc1 -fsyntax-only -verify -disable-objc-default-synthesize-properties -Wno-objc-root-class %s
Fariborz Jahanian6669db92008-11-25 17:56:43 +00002
3@interface Object
Steve Naroff6b9dfd42009-03-04 15:11:40 +00004+ (id)new;
Fariborz Jahanian6669db92008-11-25 17:56:43 +00005@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 Jahanian7ca8b062009-11-11 22:40:11 +000027- (int) Anotherobject { return _Anotherobject; }
Fariborz Jahanian6669db92008-11-25 17:56:43 +000028@end
29
30int 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 Dunbar84efc042009-01-09 01:04:21 +000037///
38
39@interface I0
Fariborz Jahanianb8607392011-08-27 21:55:47 +000040@property(readonly) int p0; // expected-note {{property declared here}}
Daniel Dunbar84efc042009-01-09 01:04:21 +000041@end
42
43@interface I0 (Cat0)
44@end
45
46@interface I0 (Cat1)
47@end
48
Fariborz Jahanianb8607392011-08-27 21:55:47 +000049@implementation I0 // expected-warning {{property 'p0' requires method 'p0' to be define}}
Daniel Dunbar84efc042009-01-09 01:04:21 +000050- (void) foo {
John McCall3c3b7f92011-10-25 17:37:35 +000051 self.p0 = 0; // expected-error {{assignment to readonly property}}
Daniel Dunbar84efc042009-01-09 01:04:21 +000052}
53@end