Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 2 | |
| 3 | // This test case tests the default behavior. |
| 4 | |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 5 | // rdar://7933061 |
| 6 | |
| 7 | @interface NSObject @end |
| 8 | |
| 9 | @interface NSArray : NSObject @end |
| 10 | |
| 11 | @interface MyClass : NSObject { |
| 12 | } |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 13 | - (void)myMethod:(NSArray *)object; |
| 14 | - (void)myMethod1:(NSObject *)object; // broken-note {{previous definition is here}} |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 15 | @end |
| 16 | |
| 17 | @implementation MyClass |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 18 | - (void)myMethod:(NSObject *)object { |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 19 | } |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 20 | - (void)myMethod1:(NSArray *)object { // broken-warning {{conflicting parameter types in implementation of 'myMethod1:': 'NSObject *' vs 'NSArray *'}} |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 21 | } |
| 22 | @end |
| 23 | |
| 24 | |
| 25 | @protocol MyProtocol @end |
| 26 | |
| 27 | @interface MyOtherClass : NSObject <MyProtocol> { |
| 28 | } |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 29 | - (void)myMethod:(id <MyProtocol>)object; // broken-note {{previous definition is here}} |
| 30 | - (void)myMethod1:(id <MyProtocol>)object; // broken-note {{previous definition is here}} |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 31 | @end |
| 32 | |
| 33 | @implementation MyOtherClass |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 34 | - (void)myMethod:(MyClass *)object { // broken-warning {{conflicting parameter types in implementation of 'myMethod:': 'id<MyProtocol>' vs 'MyClass *'}} |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 35 | } |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 36 | - (void)myMethod1:(MyClass<MyProtocol> *)object { // broken-warning {{conflicting parameter types in implementation of 'myMethod1:': 'id<MyProtocol>' vs 'MyClass<MyProtocol> *'}} |
Fariborz Jahanian | bdaae39 | 2010-10-05 21:02:11 +0000 | [diff] [blame] | 37 | } |
| 38 | @end |
John McCall | 10302c0 | 2010-10-28 02:34:38 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | |
| 42 | @interface A @end |
| 43 | @interface B : A @end |
| 44 | |
| 45 | @interface Test1 {} |
| 46 | - (void) test1:(A*) object; // broken-note {{previous definition is here}} |
| 47 | - (void) test2:(B*) object; |
| 48 | @end |
| 49 | |
| 50 | @implementation Test1 |
| 51 | - (void) test1:(B*) object {} // broken-warning {{conflicting parameter types in implementation of 'test1:': 'A *' vs 'B *'}} |
| 52 | - (void) test2:(A*) object {} |
| 53 | @end |
| 54 | |
| 55 | // rdar://problem/8597621 wants id -> A* to be an exception |
| 56 | @interface Test2 {} |
| 57 | - (void) test1:(id) object; // broken-note {{previous definition is here}} |
| 58 | - (void) test2:(A*) object; |
| 59 | @end |
| 60 | @implementation Test2 |
| 61 | - (void) test1:(A*) object {} // broken-warning {{conflicting parameter types in implementation of 'test1:': 'id' vs 'A *'}} |
| 62 | - (void) test2:(id) object {} |
| 63 | @end |
| 64 | |
| 65 | @interface Test3 {} |
| 66 | - (A*) test1; |
| 67 | - (B*) test2; // broken-note {{previous definition is here}} |
| 68 | @end |
| 69 | |
| 70 | @implementation Test3 |
| 71 | - (B*) test1 { return 0; } |
| 72 | - (A*) test2 { return 0; } // broken-warning {{conflicting return type in implementation of 'test2': 'B *' vs 'A *'}} |
| 73 | @end |
| 74 | |
| 75 | // The particular case of overriding with an id return is white-listed. |
| 76 | @interface Test4 {} |
| 77 | - (id) test1; |
| 78 | - (A*) test2; |
| 79 | @end |
| 80 | @implementation Test4 |
| 81 | - (A*) test1 { return 0; } // id -> A* is rdar://problem/8596987 |
| 82 | - (id) test2 { return 0; } |
| 83 | @end |