Nullability is disregarded when saving to a local variable and using -Wnullable-to-nonnull-conversion

Originator:stephen.groom
Number:rdar://22754136 Date Originated:18-Sep-2015 08:09 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7 (7A220)
Classification:Other Bug Reproducible:Always
 
Given the following method declarations

   - (nullable id)returnsANullable;
   - (void)takesANonnull:(nonnull id)obj;

the code

   [self takesANonnull:[self returnsANullable]];

gives the error “Implicit conversion from nullable pointer [..]”

If the result of calling returnsANullable is saved to a local variable, as in the code below, the error goes away:

   id localVariable = [self returnsANullable];
   [self takesANonnull:localVariable];

This makes the -Wnullable-to-nonnull-conversion fairly useless as it misses a large amount of possible nullable-to-nonnull mistakes.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!