Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No warning when using nonnull?

With code like this:

- (nonnull NSString *)testing {
    return nil;
}

Shouldn't I get a compiler warning? I get no warning all, which seems to make the entire nullability stuff seem useless?

like image 973
Kevin Renskers Avatar asked Nov 09 '22 18:11

Kevin Renskers


1 Answers

Well, in my opinion it should produce a warning, but I couldn't figure out to get one either.

What might be helpful though, is using Product > Analyze to run the CLANG Static Analyzer. This should give the following hint:

Null is returned from a method that is expected to return a non-null value

Another thing worth mentioning is the setting CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION which is named Incorrect Uses of Nullable values in the Apple LLVM 7.1 - Warnings - All languages section of the Build Settings.

This setting will not produce a warning for incorrect return values, but it shows a warning when using the method with incorrect parameters (e.g. nil for nonnull parameters).

This answer refers to Xcode Version 7.3.1 (7D1014)

like image 190
florieger Avatar answered Nov 27 '22 08:11

florieger