1 // RUN: %clang_cc1 -verify %s
11 - (id)retain; // expected-note 2{{instance method 'retain' is assumed to return an instance of its receiver type ('NSArray *')}}
19 // Do not infer when instance/class mismatches
25 // Do not infer when the return types mismatch.
26 - (Unrelated *)initAsUnrelated;
29 @interface NSString : NSObject
31 - (id)initWithCString:(const char*)string;
34 @interface NSArray : NSObject
41 @interface NSMutableArray : NSArray
45 + (Unrelated *)newUnrelated;
48 void test_inference() {
49 // Inference based on method family
50 __typeof__(([[NSString alloc] init])) *str = (NSString**)0;
51 __typeof__(([[[[NSString new] self] retain] autorelease])) *str2 = (NSString **)0;
52 __typeof__(([[NSString alloc] initWithCString:"blah"])) *str3 = (NSString**)0;
55 __typeof__(([[NSString new] copy])) *id1 = (id*)0;
57 // Not inferred due to instance/class mismatches
58 __typeof__(([[NSString new] newNotInferred])) *id2 = (id*)0;
59 __typeof__(([[NSString new] alloc])) *id3 = (id*)0;
60 __typeof__(([NSString self])) *id4 = (id*)0;
61 __typeof__(([NSString initWithBlarg])) *id5 = (id*)0;
63 // Not inferred due to return type mismatch
64 __typeof__(([[NSString alloc] initAsUnrelated])) *unrelated = (Unrelated**)0;
65 __typeof__(([NSBlah newUnrelated])) *unrelated2 = (Unrelated**)0;
67 NSArray *arr = [[NSMutableArray alloc] init];
68 NSMutableArray *marr = [arr retain]; // expected-warning{{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}
69 marr = [arr retain]; // expected-warning{{incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'}}