Swift type inference should read all values in an array to ascertain type

Originator:justatheory
Number:rdar://17764879 Date Originated:2014-07-22
Status:Open Resolved:
Product:Xcode Product Version:6.0 (6A267n)
Classification:Developer Tools Reproducible:Always
 
Summary:
In a for loop over an array, it looks as though type inference looks at only the first value in the array to ascertain the type. I think it should look at all the values. Example: given this code:

    for mult in [1, 2.0] {}

The type of `mult` is Int — even though there is a Double value there. However, given this code:

    for mult in [1.0, 2] {}

The type of `mult` is Double. In my opinion, these two examples should produce the same type, Double. My guess is that the analyzer looks at only the first value in the array. It should look at them all.

Version: 6.0 (6A267n)

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!