Equivalency Operator on Tuples in Swift
| Originator: | andrew.muray | ||
| Number: | rdar://26605322 | Date Originated: | 02-june-2016 |
| Status: | open | Resolved: | |
| Product: | Xcode | Product Version: | osx 10.11.5 xcode 7.3.1 |
| Classification: | Reproducible: | yes |
Andrew Muray02-Jun-2016 11:39 AM Summary: In the playground code shown below, the “==“ operator returns true. See cases: 1) A tuple defined with single element (line 5,6) is treated as the type of the first element. OK, but the tuple has more information, namely a label for the first element. As a tuple, the label name should be checked for equivalency or generate an error in lines 4 and 5. Also, one would expect that writing code such as “error1.0” or “error1.name” should work, but it doesn’t. 2) Same code is applied to tuples with two elements. Note that the ‘==‘ operator returns true. But appending to the array an element (which is equivalent) but with a different label causes an error. Steps to Reproduce: Use playground in Xcode to run the following code. // =start============================================ //: Playground - noun: a place where people can play import Foundation let error1 = (name: "item not allowed") let error2 = (nameextra: "item not allowed") ///////// print(error1 == error2) ///////// var arrayOfErrors1 = [error1] arrayOfErrors1.append(error2) print(arrayOfErrors1) //====================================================// let error3 = (name: "item not allowed", code: 1) let error4 = (nameextra: "item not allowed", code: 1) ///////// print(error3 == error4) ///////// var arrayOfErrors2 = [error3] arrayOfErrors2.append(error4) print(arrayOfErrors2) // ==end============================ Expected Results: I would like to see the following: The equivalency operator should check equivalency of labels for tuples, AND issue warning for tuples with only one element. Actual Results: Errors as result of not enough information during compiling about tuples Version: OS X 10.11.5 Xcode 7.3.1 Notes: Configuration: Using swift playground Attachments: 'report1.rtfd.zip' was successfully uploaded.
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!