__auto_type does not inherit nullability to inferred type

Originator:kyle.hickinson
Number:rdar://27062504 Date Originated:28-Jun-2016
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (8S128d)
Classification:Other Bug Reproducible:Always
 
Summary:

When you use `__auto_type` to declare a variable, it does not inherit any nullability definitions marked by the return type of the value being assigned.

Steps to Reproduce:

It is easy to reproduce this with any _Nullable return type in Foundation, for example -[NSBundle pathForResource:ofType:], which is defined as such: `- (nullable NSString *)pathForResource:(nullable NSString *)name ofType:(nullable NSString *)ext;`

This can easily be setup:

__auto_type path = [[NSBundle mainBundle] pathForResource:@“foo” ofType:@“txt”];

Expected Results:
`path` should be the type `NSString * _Nullable` because __auto_type should inherit nullability.

Actual Results:
`path` has the type `NSString *` and is assumed _Nonnull

Notes:
This can affect the use nullability warnings, since __auto_type will mark variables as assumed _Nonnull and therefore not be caught by `-Wnullable-to-nonnull-conversion`

Regression:
This is only available in the first beta of Xcode 8

Comments

Engineering has provided the following feedback regarding this issue:

We can’t implement this warning in clang as implementing it would introduce a lot of complexity. Use the static analyzer instead, which already warns about this case.

By kyle.hickinson at Aug. 31, 2016, 3:19 p.m. (reply...)

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!