Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 2 | |
Eli Friedman | 772494c | 2009-12-16 06:28:21 +0000 | [diff] [blame] | 3 | void abort(void); |
| 4 | |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 5 | @interface Subclass |
| 6 | + (int)magicNumber; |
| 7 | + (void)setMagicNumber:(int)value; |
| 8 | + (void)setFakeSetterNumber:(int)value; |
| 9 | @end |
| 10 | |
| 11 | @implementation Subclass |
| 12 | int _magicNumber = 0; |
| 13 | + (int)magicNumber { |
| 14 | return _magicNumber; |
| 15 | } |
| 16 | |
| 17 | + (void)setMagicNumber:(int)value { |
| 18 | _magicNumber = value; |
| 19 | } |
| 20 | |
| 21 | + (void)setFakeSetterNumber:(int)value { |
| 22 | _magicNumber = value; |
| 23 | } |
| 24 | |
| 25 | + (void) classMeth |
| 26 | { |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 27 | self.magicNumber = 10; |
| 28 | if (self.magicNumber != 10) |
| 29 | abort (); |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 30 | } |
| 31 | @end |
| 32 | |
| 33 | int main (void) { |
| 34 | |
| 35 | int a; |
| 36 | Subclass.magicNumber = 2 /*[Subclass setMagicNumber:2]*/; |
| 37 | if (Subclass.magicNumber != 0) |
| 38 | abort (); |
| 39 | if (Subclass.magicNumber != 2) |
| 40 | abort (); |
| 41 | Subclass.magicNumber += 3; |
| 42 | if (Subclass.magicNumber != 5) |
| 43 | abort (); |
| 44 | Subclass.magicNumber -= 5; |
| 45 | if (Subclass.magicNumber != 0) |
| 46 | abort (); |
| 47 | /* We only have a setter in the following case. */ |
| 48 | Subclass.fakeSetterNumber = 123; |
| 49 | |
| 50 | /* We read it using the other getter. */ |
| 51 | if (Subclass.magicNumber != 123) |
| 52 | abort (); |
| 53 | Subclass.fakeSetterNumber = Subclass.magicNumber; |
| 54 | if (Subclass.magicNumber != 123) |
| 55 | abort (); |
| 56 | |
| 57 | Subclass.fakeSetterNumberX = 123; // expected-error{{property 'fakeSetterNumberX' not found on object of type 'Subclass'}} |
| 58 | |
| 59 | /* Test class methods using the new syntax. */ |
| 60 | [Subclass classMeth]; |
| 61 | return 0; |
| 62 | } |