Typed collections are inconsistently type checked at creation

Originator:stephen.groom
Number:rdar://21940705 Date Originated:22-Jul-2015 03:13 PM
Status:Closed Resolved:
Product:Developer Tools Product Version:Xcode 7b4 (7A165t)
Classification:Serious Bug Reproducible:Always
 
It is possible to create collections which the compiler thinks are typed that contain objects of another type.

The following lines of code (ignoring unused variable warnings) should all trigger compiler errors as you are trying to put something other than a NSNumber into a typed NSArray of NSNumber.

    NSArray<NSNumber *> *array1 = [NSArray<NSNumber *> arrayWithObjects:@"string", nil]; //warning
    NSArray<NSNumber *> *array2 = @[@"string"]; //fine
    NSArray<NSNumber *> *array3 = [NSArray<NSNumber *> arrayWithObject:@"string"]; //warning
    NSArray<NSNumber *> *array4 = [NSArray<NSNumber *> arrayWithObjects:@999, @"string", nil]; //fine

Current behaviour:
array1 and array3 correctly show warnings about incompatible pointer types.  Curiously array2 and array4 are fine.  

Expected Behaviour
All 4 are invalid and should fail to compile.

Comments

Engineering has determined that your bug report is a duplicate of another issue and will be closed.

The open or closed status of the original bug report your issue was duplicated to appears in the yellow "Duplicate of XXXXXXXX" section of the bug reporter user interface. This section appears near the top of the right column's bug detail view just under the bug number, title, state, product and rank.

If you have any questions or concerns, please update your report directly here: http://bugreport.apple.com/.

By stephen.groom at Oct. 30, 2015, 12:06 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!