72 lines · plain
1// RUN: %clang_cc1 -verify %s2 3@interface Unrelated4@end5 6@interface NSObject7+ (id)new;8+ (id)alloc;9- (NSObject *)init;10 11- (id)retain; // expected-note 2{{instance method 'retain' is assumed to return an instance of its receiver type ('NSArray *')}}12- autorelease;13 14- (id)self;15 16- (id)copy;17- (id)mutableCopy;18 19// Do not infer when instance/class mismatches20- (id)newNotInferred;21- (id)alloc;22+ (id)initWithBlarg;23+ (id)self;24 25// Do not infer when the return types mismatch.26- (Unrelated *)initAsUnrelated;27@end28 29@interface NSString : NSObject30- (id)init;31- (id)initWithCString:(const char*)string;32@end33 34@interface NSArray : NSObject35- (unsigned)count;36@end37 38@interface NSBlah 39@end40 41@interface NSMutableArray : NSArray42@end43 44@interface NSBlah ()45+ (Unrelated *)newUnrelated;46@end47 48void test_inference() {49 // Inference based on method family50 __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;53 54 // Not inferred55 __typeof__(([[NSString new] copy])) *id1 = (id*)0;56 57 // Not inferred due to instance/class mismatches58 __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;62 63 // Not inferred due to return type mismatch64 __typeof__(([[NSString alloc] initAsUnrelated])) *unrelated = (Unrelated**)0;65 __typeof__(([NSBlah newUnrelated])) *unrelated2 = (Unrelated**)0; 66 67 NSArray *arr = [[NSMutableArray alloc] init];68 NSMutableArray *marr = [arr retain]; // expected-error{{incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *'}}69 marr = [arr retain]; // expected-error{{incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray *'}}70 arr = [marr retain];71}72