It is possible to send NSArray* to a method expecting a NSArray<T>*

Originator:stephen.groom
Number:rdar://21940777 Date Originated:22-Jul-2015 03:19 PM
Status:Behaves correctly Resolved:24-Jul-2015 08:01 PM
Product:Developer Tools Product Version:Xcode 7b4 (7A165t)
Classification:Serious Bug Reproducible:Always
 
Summary:
Methods that accept an NSArray<T>* also accept NSArray* without warning or error.

Steps to Reproduce:
Consider the following code

@implementation GenericsTest

- (void)genericsTest
{
    [self testMethod:@[@"string"]]; //fine

    NSArray *untypedArray = @[self, @123, @"string"];
    [self testMethod:untypedArray]; //fine
}

- (void)testMethod:(NSArray<NSNumber *> *)numberArray
{ }

@end

Current Behaviour:
There is no warning or error

Expected behaviour:
Both method calls should produce errors as the type of the parameter is not NSArray<NSNumber*>* but NSArray* which can contain any type.

Comments

Apple Developer Relations

This issue behaves as intended based on the following:

This is correct behavior. Unspecialized generic types silently convert to specialized generic types. There is no warning for such cases because this warning would have an extremely high false-positive rate.

We are now closing this bug report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

By stephen.groom at July 28, 2015, 9:21 a.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!