The use of the overloaded += operator in Swift is inconsistent and confusing with Arrays

Originator:rclconcepts
Number:rdar://17151420 Date Originated:6/4/2014
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.0(6A215l)
Classification:Other Bug Reproducible:Always
 
--
Using the += operator on an array sometimes results in the array items on the RHS being added to the array on the LHS, and sometimes results in the whole RHS array being added to the LHS. (in objc terms, sometimes addObject: is called and sometimes addObjectFromArray: is called).

it appears using literals VS variable VS constants can really change the behavior of the += operator. This causes code to be unpredictable and hard to read at a glance.

--
See the following two images for an example:
1. http://cl.ly/image/3j2N3h0w2J3Z/o
2. http://cl.ly/image/3q321j0I0p3m

--
+= should either always call addObject or addObjectsFromArray: enforcing types where it makes sense. Variables vs constants vs inline literals shouldn't change the behavior.

Comments

A video highlight some more strangeness. https://jumpshare.com/v/mhZzAAfCk6KRGne2dsKD

By rclconcepts at June 5, 2014, 1:10 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!