[PATCH] D36790: [ObjC] Messages to 'self' in class methods should use class method dispatch to avoid multiple method ambiguities

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 16 09:31:16 PDT 2017

arphaman added a comment.

@rjmccall Do you think that the rules for the return types in overridden methods that return `instancetype` should be strengthened first? For example, if we have the following code:

  @interface Unrelated
  - (void)method:(int)x;
  @interface CallsSelfSuper: NSObject
  + (void) target;
  - (void) method:(CallsSelfSuper *)x;
  @implementation CallsSelfSuper
  + (void) target {
    [[self alloc] method: 12]; // Can't assume 'method' is CallsSelfSuper's 'method' declaration unless we guarantee that OverrideAlloc's alloc actually returns `instancetype` and not id.
  @interface OverrideAlloc: CallsSelfSuper
  @implementation OverrideAlloc
  + (id) alloc {
    return [NSString alloc];

We can't really make any assumptions about what `[self alloc]` will return. But in my opinion we could assume that `[self alloc]` will return a `CallsSelfSuper *` if we could ensure that methods that override methods that return `instancetype` will compile only if they return `instancetype` type as well.



More information about the cfe-commits mailing list