Commits

Jordan Rose committed 8247c2d3575
If imported calls return nil for 'NSArray * __nonnull', pretend it was []. ...and similar for NSDictionary and NSSet. For APIs that don't have a reason to distinguish "empty" and "absent" cases, we encourage standardizing on "empty" and marking the result as non-optional (or in Objective-C, __nonnull). However, there are system APIs whose implementations currently do return nil rather than an empty collection instance. In these cases, we recommend /changing/ the API to return the appropriate "empty" value instead. However, this can cause problems for backwards-deployment: while the API is truly non-optional on system vN, a program may encounter a nil return value if run on system vN-1. Objective-C can generally deal with this (especially if the only thing you do is ask for the count or try to iterate over the collection) but Swift can't. Therefore, we've decided to "play nice" and accept nil return values for the collection types (NSArray, NSDictionary, and NSSet) and implicitly treat them as "empty" values if they are the result of an imported function or method. Note that the current implementation has a hole regarding subscript getters, since we still make an AST-level thunk for these in the Clang importer. We can probably get rid of those these days, but I didn't want to touch them at this point. It seems unlikely that there will be a subscript that (a) is for a collection type, and (b) mistakenly returned nil in the past rather than an empty collection. There's another hole where an ObjC client calls one of these mistakenly-nil- returning methods and then immediately hands the result off by calling a Swift method. However, we have to draw the line somewhere. (We're actually going to do this for strings as well; coming soon.) rdar://problem/19734621 Swift SVN r26479