compiler/analyzer does not catch init methods returning null with nonnull

Originator:nobrien
Number:rdar://31262790 Date Originated:03/26/2017
Status:Open Resolved:
Product:Xcode Product Version:8.2
Classification:Serious Bug Reproducible:Always
 
Summary:
compiler/analyzer does not catch init methods returning null with nonnull - very simple

This means we can't catch bugs at compile time due to nullability contracts being broken

See attached screenshot for crystal clear repro

Steps to Reproduce:

1) Have this init method:

- (nonnull instancetype)initWithCondition:(BOOL)condition
{
    if (condition) {
        return nil;
    }
    return [self init];
}

2) set CLANG_ANALYZER_NONNULL to YES for the project being analyzed

Expected Results:

static analyzer (or, even better, the compiler) will have warning where "return nil" line happens:
"nil returned from a method that is expected to return a non-null value"

Actual Results:
No such warning, expect crashing in production when nil is returned and Swift is the consumer language

Comments

Screenshot is of the following:

- (nonnull instancetype)initWithCondition:(BOOL)condition
{
    if (condition) {
        return nil; // no warning
    }
    return [self init];
}

- (nonnull instancetype)methodWithCondition:(BOOL)condition
{
    if (condition) {
        return nil; // warning is present
    }
    return [self init];
}

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!