arphaman added a comment.

In https://reviews.llvm.org/D36790#843450, @arphaman wrote:

> @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;
>   @end
>  
>   @interface CallsSelfSuper: NSObject
>   + (void) target;
>   - (void) method:(CallsSelfSuper *)x;
>   @end
>  
>   @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.
>   }
>   @end
>  
>   @interface OverrideAlloc: CallsSelfSuper
>   @end
>  
>   @implementation OverrideAlloc
>   + (id) alloc {
>     return [NSString alloc];
>   }
>   @end 
>
>
> 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.


I've looked at this again and it seems that Clang already has warnings in cases 
like this, so `instancetype` is already treated as somewhat of an inherited 
requirement. I now think it should be add the behavior in this patch without 
imposing additional restrictions.


Repository:
  rL LLVM

https://reviews.llvm.org/D36790



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to