make isEqualToString: parameter nullability attribute 'nullable' while preserving current behavior

Originator:kbeitz
Number:rdar://39951118 Date Originated:2018.05.03
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 9.3
Classification:Bug Reproducible:Yes
 
Summary: in the SDK, the declaration -[NSString isEqualToString:(NSString *)s] falls within an NS_ASSUME_NONNULL_BEGIN/NS_ASSUME_NONNULL_END block, and thus causes the parameter to be nil.




Steps to Reproduce:
(a)
NSString *x = @"test"; // line 1
if ([x isEqualToString:nil]) { // line 2
    NSLog(@"error: x is not equal to nil"); // line 3
} // line 4

(b)
NSString *x = @"test"; // line 1
if ([x isEqualToString:(NSString * _Nonnull)nil]) { // line 2
    NSLog(@"error: x is not equal to nil"); // line 3
} // line 4

(c)
NSString *RandomNullableString()
{
    return (arc4random_uniform(2) < 1) ? @"test" : nil;
}

NSString *x = @"test"; // line 1
NSString *y = RandomNullableString(); // line 2
if ([x isEqualToString:y]) { // line 3
    NSLog(@"error: x is not equal to nil"); // line 4
} // line 5

Expected Results (based on preference for nullable parameter):
(a) no compiler/analyzer issues; conditional line 2 is NO, line 3 is not executed
(b) no compiler/analyzer issues; conditional line 2 is NO, line 3 is not executed
(c) no compiler/analyzer issues; conditional line 3 is YES half the time and NO half the time, line 4 is not executed

Actual Results:
(a) compiler error (parameter requires non-nil value)
(b) works as expected
(c) some instances (haven't figured out why) result in an analyzer issue about a potential nil being passed

Version/Build: Xcode 9.3


Configuration: macOS High Sierra (10.13.4), MacBook Pro (Retina, 15-inch, Mid 2015)

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!