xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/property-user-setter.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc@interface I0
4f4a2713aSLionel Sambuc@property(readonly) int x;
5f4a2713aSLionel Sambuc@property(readonly) int y;
6f4a2713aSLionel Sambuc@property(readonly) int z;
7f4a2713aSLionel Sambuc-(void) setY: (int) y0;
8f4a2713aSLionel Sambuc@end
9f4a2713aSLionel Sambuc
10f4a2713aSLionel Sambuc@interface I0 (Cat0)
11f4a2713aSLionel Sambuc-(void) setX: (int) a0;
12f4a2713aSLionel Sambuc@end
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc@implementation I0
15f4a2713aSLionel Sambuc@dynamic x;
16f4a2713aSLionel Sambuc@dynamic y;
17f4a2713aSLionel Sambuc@dynamic z;
18f4a2713aSLionel Sambuc-(void) setY: (int) y0{}
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc-(void) im0 {
21f4a2713aSLionel Sambuc  self.x = 0;
22f4a2713aSLionel Sambuc  self.y = 2;
23f4a2713aSLionel Sambuc  self.z = 2; // expected-error {{assignment to readonly property}}
24f4a2713aSLionel Sambuc}
25f4a2713aSLionel Sambuc@end
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc// Test when property is 'readonly' but it has a setter in
28f4a2713aSLionel Sambuc// its implementation only.
29f4a2713aSLionel Sambuc@interface I1  {
30f4a2713aSLionel Sambuc}
31f4a2713aSLionel Sambuc@property(readonly) int identifier;
32f4a2713aSLionel Sambuc@end
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc@implementation I1
36f4a2713aSLionel Sambuc@dynamic identifier;
37f4a2713aSLionel Sambuc- (void)setIdentifier:(int)ident {}
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc- (id)initWithIdentifier:(int)Arg {
40f4a2713aSLionel Sambuc    self.identifier = 0;
41f4a2713aSLionel Sambuc}
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc@end
44f4a2713aSLionel Sambuc
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc// Also in a category implementation
47f4a2713aSLionel Sambuc@interface I1(CAT)
48f4a2713aSLionel Sambuc@property(readonly) int rprop;
49f4a2713aSLionel Sambuc@end
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc
52f4a2713aSLionel Sambuc@implementation I1(CAT)
53f4a2713aSLionel Sambuc@dynamic rprop;
54f4a2713aSLionel Sambuc- (void)setRprop:(int)ident {}
55f4a2713aSLionel Sambuc
56f4a2713aSLionel Sambuc- (id)initWithIdentifier:(int)Arg {
57f4a2713aSLionel Sambuc    self.rprop = 0;
58f4a2713aSLionel Sambuc}
59f4a2713aSLionel Sambuc
60f4a2713aSLionel Sambuc@end
61f4a2713aSLionel Sambuc
62f4a2713aSLionel Sambucstatic int g_val;
63f4a2713aSLionel Sambuc
64f4a2713aSLionel Sambuc@interface Root
65f4a2713aSLionel Sambuc+ alloc;
66f4a2713aSLionel Sambuc- init;
67f4a2713aSLionel Sambuc@end
68f4a2713aSLionel Sambuc
69f4a2713aSLionel Sambuc@interface Subclass : Root
70f4a2713aSLionel Sambuc{
71f4a2713aSLionel Sambuc    int setterOnly;
72f4a2713aSLionel Sambuc}
73f4a2713aSLionel Sambuc- (void) setSetterOnly:(int)value;
74f4a2713aSLionel Sambuc@end
75f4a2713aSLionel Sambuc
76f4a2713aSLionel Sambuc@implementation Subclass
77f4a2713aSLionel Sambuc- (void) setSetterOnly:(int)value {
78f4a2713aSLionel Sambuc    setterOnly = value;
79f4a2713aSLionel Sambuc    g_val = setterOnly;
80f4a2713aSLionel Sambuc}
81f4a2713aSLionel Sambuc@end
82f4a2713aSLionel Sambuc
83f4a2713aSLionel Sambuc@interface C {}
84f4a2713aSLionel Sambuc// - (int)Foo;
85f4a2713aSLionel Sambuc- (void)setFoo:(int)value;
86f4a2713aSLionel Sambuc@end
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambucvoid g(int);
89f4a2713aSLionel Sambuc
90f4a2713aSLionel Sambucvoid f(C *c) {
91f4a2713aSLionel Sambuc    c.Foo = 17; // OK
92f4a2713aSLionel Sambuc    g(c.Foo); // expected-error {{no getter method for read from property}}
93f4a2713aSLionel Sambuc}
94f4a2713aSLionel Sambuc
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambucvoid abort(void);
97f4a2713aSLionel Sambucint main (void) {
98f4a2713aSLionel Sambuc    Subclass *x = [[Subclass alloc] init];
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc    x.setterOnly = 4;   // OK
101f4a2713aSLionel Sambuc    if (g_val != 4)
102f4a2713aSLionel Sambuc      abort ();
103f4a2713aSLionel Sambuc    return 0;
104f4a2713aSLionel Sambuc}
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc// rdar://11363363
107f4a2713aSLionel Sambuc@interface rdar11363363
108f4a2713aSLionel Sambuc{
109f4a2713aSLionel Sambuc  id R;
110f4a2713aSLionel Sambuc}
111f4a2713aSLionel Sambuc@property (copy) id p;
112f4a2713aSLionel Sambuc@property (copy) id r;
113f4a2713aSLionel Sambuc@property (copy) id Q;
114f4a2713aSLionel Sambuc@property (copy) id t; // expected-note 2 {{property declared here}}
115f4a2713aSLionel Sambuc@property (copy) id T; // expected-note 2 {{property declared here}}
116f4a2713aSLionel Sambuc@property (copy) id Pxyz; // expected-note 2 {{property declared here}}
117f4a2713aSLionel Sambuc@property (copy) id pxyz; // expected-note 2 {{property declared here}}
118f4a2713aSLionel Sambuc@end
119f4a2713aSLionel Sambuc
120f4a2713aSLionel Sambuc@implementation rdar11363363
121f4a2713aSLionel Sambuc@synthesize p;
122f4a2713aSLionel Sambuc@synthesize r;
123f4a2713aSLionel Sambuc@synthesize Q;
124f4a2713aSLionel Sambuc@synthesize t, T;
125f4a2713aSLionel Sambuc@synthesize Pxyz, pxyz;
126f4a2713aSLionel Sambuc- (id) Meth {
127*0a6a1f1dSLionel Sambuc  self.P = 0; // expected-warning {{property 'P' not found on object of type 'rdar11363363 *'; did you mean to access property p?}}
128*0a6a1f1dSLionel Sambuc  self.q = 0; // expected-warning {{property 'q' not found on object of type 'rdar11363363 *'; did you mean to access property Q?}}
129f4a2713aSLionel Sambuc// rdar://11528439
130f4a2713aSLionel Sambuc  self.t = 0; // expected-error {{synthesized properties 't' and 'T' both claim setter 'setT:'}}
131f4a2713aSLionel Sambuc  self.T = 0; // expected-error {{synthesized properties 'T' and 't' both claim setter 'setT:'}}
132f4a2713aSLionel Sambuc  self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}}
133f4a2713aSLionel Sambuc  self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}}
134*0a6a1f1dSLionel Sambuc  self.r = 0;
135*0a6a1f1dSLionel Sambuc  return self.R; // expected-error {{no getter method for read from property}} \
136*0a6a1f1dSLionel Sambuc                 // expected-warning {{property 'R' not found on object of type 'rdar11363363 *'; did you mean to access property r?}}
137f4a2713aSLionel Sambuc}
138f4a2713aSLionel Sambuc@end
139f4a2713aSLionel Sambuc
140f4a2713aSLionel Sambuc// rdar://11499742
141f4a2713aSLionel Sambuc@class BridgeFormatter;
142f4a2713aSLionel Sambuc
143f4a2713aSLionel Sambuc@interface FMXBridgeFormatter
144f4a2713aSLionel Sambuc
145f4a2713aSLionel Sambuc@property(assign, readwrite, getter=formatter, setter=setFormatter:) BridgeFormatter* cppFormatter;
146f4a2713aSLionel Sambuc
147f4a2713aSLionel Sambuc@end
148f4a2713aSLionel Sambuc
149f4a2713aSLionel Sambuc@implementation FMXBridgeFormatter
150f4a2713aSLionel Sambuc@synthesize cppFormatter;
151f4a2713aSLionel Sambuc
152f4a2713aSLionel Sambuc- (void) dealloc
153f4a2713aSLionel Sambuc{
154f4a2713aSLionel Sambuc self.formatter = 0;
155f4a2713aSLionel Sambuc}
156f4a2713aSLionel Sambuc@end
157f4a2713aSLionel Sambuc
158