blob: d977d1544ea1f37ae853256257abc11d9d1cbacd [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
Fariborz Jahanian21292122009-01-10 18:43:55 +00002
3@interface I0
4@property(readonly) int x;
5@property(readonly) int y;
6@property(readonly) int z;
7-(void) setY: (int) y0;
8@end
9
10@interface I0 (Cat0)
11-(void) setX: (int) a0;
12@end
13
14@implementation I0
15@dynamic x;
16@dynamic y;
17@dynamic z;
18-(void) setY: (int) y0{}
19
20-(void) im0 {
21 self.x = 0;
22 self.y = 2;
John McCall3c3b7f92011-10-25 17:37:35 +000023 self.z = 2; // expected-error {{assignment to readonly property}}
Fariborz Jahanian21292122009-01-10 18:43:55 +000024}
25@end
Fariborz Jahaniand1fa6442009-01-12 19:55:42 +000026
27// Test when property is 'readonly' but it has a setter in
28// its implementation only.
29@interface I1 {
30}
31@property(readonly) int identifier;
32@end
33
34
35@implementation I1
36@dynamic identifier;
37- (void)setIdentifier:(int)ident {}
38
39- (id)initWithIdentifier:(int)Arg {
40 self.identifier = 0;
41}
42
43@end
44
45
46// Also in a category implementation
47@interface I1(CAT)
48@property(readonly) int rprop;
49@end
50
51
52@implementation I1(CAT)
53@dynamic rprop;
54- (void)setRprop:(int)ident {}
55
56- (id)initWithIdentifier:(int)Arg {
57 self.rprop = 0;
58}
59
60@end
61
Steve Naroff1ca66942009-03-11 13:48:17 +000062static int g_val;
63
64@interface Root
65+ alloc;
66- init;
67@end
68
69@interface Subclass : Root
70{
71 int setterOnly;
72}
Fariborz Jahanian99130e52010-12-22 19:46:35 +000073- (void) setSetterOnly:(int)value;
Steve Naroff1ca66942009-03-11 13:48:17 +000074@end
75
76@implementation Subclass
77- (void) setSetterOnly:(int)value {
78 setterOnly = value;
79 g_val = setterOnly;
80}
81@end
82
Fariborz Jahaniandd0cb902010-01-19 17:48:02 +000083@interface C {}
84// - (int)Foo;
Fariborz Jahanian99130e52010-12-22 19:46:35 +000085- (void)setFoo:(int)value;
Fariborz Jahaniandd0cb902010-01-19 17:48:02 +000086@end
87
John McCall3c3b7f92011-10-25 17:37:35 +000088void g(int); // expected-note {{passing argument to parameter here}}
Fariborz Jahaniandd0cb902010-01-19 17:48:02 +000089
90void f(C *c) {
Fariborz Jahanian99130e52010-12-22 19:46:35 +000091 c.Foo = 17; // OK
92 g(c.Foo); // expected-error {{expected getter method not found on object of type 'C *'}}
Fariborz Jahaniandd0cb902010-01-19 17:48:02 +000093}
94
95
Eli Friedman772494c2009-12-16 06:28:21 +000096void abort(void);
Steve Naroff1ca66942009-03-11 13:48:17 +000097int main (void) {
98 Subclass *x = [[Subclass alloc] init];
99
Fariborz Jahanian99130e52010-12-22 19:46:35 +0000100 x.setterOnly = 4; // OK
Steve Naroff1ca66942009-03-11 13:48:17 +0000101 if (g_val != 4)
102 abort ();
103 return 0;
104}
Fariborz Jahaniand5f1bd22012-05-24 18:29:41 +0000105
106// rdar://11363363
107@interface rdar11363363
108{
109 id R;
110}
111@property (copy) id p;
112@property (copy) id r;
113@property (copy) id Q;
114@property (copy) id t;
115@property (copy) id T;
116@end
117
118@implementation rdar11363363
119@synthesize p;
120@synthesize r;
121@synthesize Q;
122@synthesize t, T;
123- (id) Meth {
124 self.P = 0; // expected-error {{property 'P' not found on object of type 'rdar11363363 *'}}
125 self.q = 0; // expected-error {{property 'q' not found on object of type 'rdar11363363 *'}}
126 self.t = 0; // OK
127 self.T = 0; // OK
128 self.R = 0; // expected-error {{property 'R' not found on object of type 'rdar11363363 *'; did you mean to access ivar 'R'?}}
129 return self.R; // expected-error {{property 'R' not found on object of type 'rdar11363363 *'; did you mean to access ivar 'R'?}}
130}
131@end
132