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