Patrick Beard | b2f6820 | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s |
Fariborz Jahanian | 2129212 | 2009-01-10 18:43:55 +0000 | [diff] [blame] | 2 | |
| 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 McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 23 | self.z = 2; // expected-error {{assignment to readonly property}} |
Fariborz Jahanian | 2129212 | 2009-01-10 18:43:55 +0000 | [diff] [blame] | 24 | } |
| 25 | @end |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 26 | |
| 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 Naroff | 1ca6694 | 2009-03-11 13:48:17 +0000 | [diff] [blame] | 62 | static int g_val; |
| 63 | |
| 64 | @interface Root |
| 65 | + alloc; |
| 66 | - init; |
| 67 | @end |
| 68 | |
| 69 | @interface Subclass : Root |
| 70 | { |
| 71 | int setterOnly; |
| 72 | } |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 73 | - (void) setSetterOnly:(int)value; |
Steve Naroff | 1ca6694 | 2009-03-11 13:48:17 +0000 | [diff] [blame] | 74 | @end |
| 75 | |
| 76 | @implementation Subclass |
| 77 | - (void) setSetterOnly:(int)value { |
| 78 | setterOnly = value; |
| 79 | g_val = setterOnly; |
| 80 | } |
| 81 | @end |
| 82 | |
Fariborz Jahanian | dd0cb90 | 2010-01-19 17:48:02 +0000 | [diff] [blame] | 83 | @interface C {} |
| 84 | // - (int)Foo; |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 85 | - (void)setFoo:(int)value; |
Fariborz Jahanian | dd0cb90 | 2010-01-19 17:48:02 +0000 | [diff] [blame] | 86 | @end |
| 87 | |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 88 | void g(int); // expected-note {{passing argument to parameter here}} |
Fariborz Jahanian | dd0cb90 | 2010-01-19 17:48:02 +0000 | [diff] [blame] | 89 | |
| 90 | void f(C *c) { |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 91 | c.Foo = 17; // OK |
| 92 | g(c.Foo); // expected-error {{expected getter method not found on object of type 'C *'}} |
Fariborz Jahanian | dd0cb90 | 2010-01-19 17:48:02 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
Eli Friedman | 772494c | 2009-12-16 06:28:21 +0000 | [diff] [blame] | 96 | void abort(void); |
Steve Naroff | 1ca6694 | 2009-03-11 13:48:17 +0000 | [diff] [blame] | 97 | int main (void) { |
| 98 | Subclass *x = [[Subclass alloc] init]; |
| 99 | |
Fariborz Jahanian | 99130e5 | 2010-12-22 19:46:35 +0000 | [diff] [blame] | 100 | x.setterOnly = 4; // OK |
Steve Naroff | 1ca6694 | 2009-03-11 13:48:17 +0000 | [diff] [blame] | 101 | if (g_val != 4) |
| 102 | abort (); |
| 103 | return 0; |
| 104 | } |
Fariborz Jahanian | d5f1bd2 | 2012-05-24 18:29:41 +0000 | [diff] [blame] | 105 | |
| 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; |
Fariborz Jahanian | b5b155c | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 114 | @property (copy) id t; // expected-note 2 {{property declared here}} |
| 115 | @property (copy) id T; // expected-note 2 {{property declared here}} |
| 116 | @property (copy) id Pxyz; // expected-note 2 {{property declared here}} |
| 117 | @property (copy) id pxyz; // expected-note 2 {{property declared here}} |
Fariborz Jahanian | d5f1bd2 | 2012-05-24 18:29:41 +0000 | [diff] [blame] | 118 | @end |
| 119 | |
| 120 | @implementation rdar11363363 |
| 121 | @synthesize p; |
| 122 | @synthesize r; |
| 123 | @synthesize Q; |
| 124 | @synthesize t, T; |
Fariborz Jahanian | b5b155c | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 125 | @synthesize Pxyz, pxyz; |
Fariborz Jahanian | d5f1bd2 | 2012-05-24 18:29:41 +0000 | [diff] [blame] | 126 | - (id) Meth { |
Fariborz Jahanian | 59a9881 | 2012-05-30 17:33:54 +0000 | [diff] [blame] | 127 | self.P = 0; |
| 128 | self.q = 0; |
Fariborz Jahanian | b5b155c | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 129 | // rdar://11528439 |
Fariborz Jahanian | cba0ebc | 2012-05-26 16:10:06 +0000 | [diff] [blame] | 130 | self.t = 0; // expected-error {{synthesized properties 't' and 'T' both claim setter 'setT:'}} |
| 131 | self.T = 0; // expected-error {{synthesized properties 'T' and 't' both claim setter 'setT:'}} |
| 132 | self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}} |
| 133 | self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}} |
Fariborz Jahanian | 59a9881 | 2012-05-30 17:33:54 +0000 | [diff] [blame] | 134 | self.R = 0; |
| 135 | return self.R; // expected-error {{expected getter method not found on object of type 'rdar11363363 *'}} |
| 136 | } |
| 137 | @end |
| 138 | |
| 139 | // rdar://11499742 |
| 140 | @class BridgeFormatter; |
| 141 | |
| 142 | @interface FMXBridgeFormatter |
| 143 | |
| 144 | @property(assign, readwrite, getter=formatter, setter=setFormatter:) BridgeFormatter* cppFormatter; |
| 145 | |
| 146 | @end |
| 147 | |
| 148 | @implementation FMXBridgeFormatter |
| 149 | @synthesize cppFormatter; |
| 150 | |
| 151 | - (void) dealloc |
| 152 | { |
| 153 | self.formatter = 0; |
Fariborz Jahanian | d5f1bd2 | 2012-05-24 18:29:41 +0000 | [diff] [blame] | 154 | } |
| 155 | @end |
| 156 | |