Swift sometimes pick incorrect `==` function to call
Originator: | xlchen1291 | ||
Number: | rdar://17340722 | Date Originated: | 17-Jun-2014 |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | |
Classification: | Reproducible: |
Summary: given this code let a: Array<Int>? = [1] let b: Array<Int>? = [1] (a!) == (b!) let a2 = a! let b2 = b! a2 == b! // evaluate to true b! == a2 // evaluate to false ------- and this code let s1 : Slice<Int> = Slice(count: 1, repeatedValue:1) let s2 : Slice<Int> = Slice(count: 1, repeatedValue:1) var b1 = s1[0..1] == s2 // false var b2 = s1 == s2 // true ----- the compiler sometimes decide to use @transparent func ==(lhs: CConstVoidPointer, rhs: CConstVoidPointer) -> Bool to compare value, which give unexpected and incorrect result Steps to Reproduce: xcrun swift Welcome to Swift! Type :help for assistance. 1> let a: Array<Int>? = [1] a: Int[]? = size=1 { [0] = 1 } 2> let b: Array<Int>? = [1] b: Int[]? = size=1 { [0] = 1 } 3> let a2 = a! a2: Int[] = size=1 { [0] = 1 } 4> let b2 = b! b2: Int[] = size=1 { [0] = 1 } 5> 6> a2 == b! $R1: Bool = true 7> b! == a2 $R2: Bool = false 8> (a2 == b!) == (b! == a2) $R3: (Bool) = false 9> import Foundation 10> a2 == b! $R9: Bool = true 11> b! == a2 <REPL>:11:4: error: ambiguous use of operator '==' b! == a2 ^ Swift.==:1:19: note: found this candidate @transparent func ==(lhs: CConstVoidPointer, rhs: CConstVoidPointer) -> Bool ^ Foundation.==:1:6: note: found this candidate func ==(lhs: NSObject, rhs: NSObject) -> Bool Expected Results: b! == a2 is true and (a2 == b!) == (b! == a2) is true Actual Results: b! == a2 is false and (a2 == b!) == (b! == a2) is false Version: xcrun swift --version Swift version 1.0 (swift-600.0.34.4.5) Target: x86_64-apple-darwin14.0.0 Notes: http://stackoverflow.com/questions/24260900/equality-of-unwrapped-optional-arrays-in-swift/24261366#24261366 http://stackoverflow.com/questions/24238478/what-is-the-slice-compare-logic-in-swift/24239556#24239556 Configuration: Attachments:
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!