| 1 |
// RUN: %check_clang_tidy %s objc-super-self %t |
| 2 |
|
| 3 |
@interface NSObject |
| 4 |
- (instancetype)init; |
| 5 |
- (instancetype)self; |
| 6 |
@end |
| 7 |
|
| 8 |
@interface NSObjectDerivedClass : NSObject |
| 9 |
@end |
| 10 |
|
| 11 |
@implementation NSObjectDerivedClass |
| 12 |
|
| 13 |
- (instancetype)init { |
| 14 |
return [super self]; |
| 15 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 16 |
// CHECK-FIXES: return [super init]; |
| 17 |
} |
| 18 |
|
| 19 |
- (instancetype)initWithObject:(NSObject *)obj { |
| 20 |
self = [super self]; |
| 21 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 22 |
// CHECK-FIXES: self = [super init]; |
| 23 |
if (self) { |
| 24 |
// ... |
| 25 |
} |
| 26 |
return self; |
| 27 |
} |
| 28 |
|
| 29 |
#define INITIALIZE() [super self] |
| 30 |
|
| 31 |
- (instancetype)initWithObject:(NSObject *)objc a:(int)a { |
| 32 |
return INITIALIZE(); |
| 33 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 34 |
// CHECK-FIXES: return INITIALIZE(); |
| 35 |
} |
| 36 |
|
| 37 |
#define INITIALIZER_IMPL() return [super self] |
| 38 |
|
| 39 |
- (instancetype)initWithObject:(NSObject *)objc b:(int)b { |
| 40 |
INITIALIZER_IMPL(); |
| 41 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 42 |
// CHECK-FIXES: INITIALIZER_IMPL(); |
| 43 |
} |
| 44 |
|
| 45 |
#define INITIALIZER_METHOD self |
| 46 |
|
| 47 |
- (instancetype)initWithObject:(NSObject *)objc c:(int)c { |
| 48 |
return [super INITIALIZER_METHOD]; |
| 49 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 50 |
// CHECK-FIXES: return [super INITIALIZER_METHOD]; |
| 51 |
} |
| 52 |
|
| 53 |
#define RECEIVER super |
| 54 |
|
| 55 |
- (instancetype)initWithObject:(NSObject *)objc d:(int)d { |
| 56 |
return [RECEIVER self]; |
| 57 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self] |
| 58 |
// CHECK-FIXES: return [RECEIVER self]; |
| 59 |
} |
| 60 |
|
| 61 |
- (instancetype)foo { |
| 62 |
return [super self]; |
| 63 |
} |
| 64 |
|
| 65 |
- (instancetype)bar { |
| 66 |
return [self self]; |
| 67 |
} |
| 68 |
|
| 69 |
@end |
| 70 |
|
| 71 |
@interface RootClass |
| 72 |
- (instancetype)init; |
| 73 |
- (instancetype)self; |
| 74 |
@end |
| 75 |
|
| 76 |
@interface NotNSObjectDerivedClass : RootClass |
| 77 |
@end |
| 78 |
|
| 79 |
@implementation NotNSObjectDerivedClass |
| 80 |
|
| 81 |
- (instancetype)init { |
| 82 |
return [super self]; |
| 83 |
} |
| 84 |
|
| 85 |
@end |
| 86 |
|