mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 05:26:06 +00:00

use the pointer to the class as the result type of the message Prior to this commit, messages to self in class methods were treated as instance methods to a Class value. When these methods returned instancetype the compiler only saw id through the instancetype, and not the Interface *. This caused problems when that return value was a receiver in a message send, as the compiler couldn't select the right method declaration and had to rely on a selection from the global method pool. This commit modifies the semantics of such message sends and uses class messages that are dispatched to the interface that corresponds to the class that contains the class method. This ensures that instancetypes are correctly interpreted by the compiler. This change is safe under ARC (as self can't be reassigned), however, it also applies to MRR code as we are assuming that the user isn't doing anything unreasonable. rdar://20940997 Differential Revision: https://reviews.llvm.org/D36790 llvm-svn: 349841
40 lines
699 B
Objective-C
40 lines
699 B
Objective-C
// RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify %s
|
|
// RUN: %clang_cc1 -Wobjc-multiple-method-names -x objective-c -verify -fobjc-arc %s
|
|
// expected-no-diagnostics
|
|
|
|
@interface NSObj
|
|
|
|
+ (instancetype) alloc;
|
|
|
|
+ (_Nonnull instancetype) globalObject;
|
|
|
|
@end
|
|
|
|
@interface SelfAllocReturn: NSObj
|
|
|
|
- (instancetype)initWithFoo:(int)x;
|
|
|
|
@end
|
|
|
|
@interface SelfAllocReturn2: NSObj
|
|
|
|
- (instancetype)initWithFoo:(SelfAllocReturn *)x;
|
|
|
|
@end
|
|
|
|
@implementation SelfAllocReturn
|
|
|
|
- (instancetype)initWithFoo:(int)x {
|
|
return self;
|
|
}
|
|
|
|
+ (instancetype) thingWithFoo:(int)x {
|
|
return [[self alloc] initWithFoo: x];
|
|
}
|
|
|
|
+ (void) initGlobal {
|
|
(void)[[self globalObject] initWithFoo: 20];
|
|
}
|
|
|
|
@end
|