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