You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-1535 No == overload exists for comparing optional arrays.
Issue Description:
In Swift 4 (Xcode 9.1) I can't compare two optionals for equality (self.lineForms == item2.lineForms, where lineForms is [String]?). And indeed Equatable protocol only contains static func == (lhs: Self, rhs: Self) -> Bool, no optional versions. It's a bug, because https://github.com/apple/swift-evolution/blob/master/proposals/0121-remove-optional-comparison-operators.md clearly states "Variants of == and != which accept optional operands are still useful, and their results unsurprising, so they will remain.". And indeed, nil == nil is true, nil == non-nil is false (as well as non-nil == nil) and non-nil == non-nil should perform an actual comparison. I even can't create an extension to Equatable, because an error is shown that asks for at least one parameter of == to be of type Self (non-optional). Obviously, it's still possible to write (self.lineForms == nil && item2.lineForms == nil) || (self.lineForms ![](= nil && item2.lineForms )= nil && self.lineForms![]( == item2.lineForms)), but this doesn't look good and there's no reason to use this instead of just a single == comparison.
The text was updated successfully, but these errors were encountered:
That hasn't ever worked, except that in some older Xcodes (well before Xcode 9.1) it converted the arrays to NSArrays and then called isEqual, which is probably not what you want. The feature to fix this is "conditional conformances", which is being actively worked on.
Environment
Xcode 9.1
Additional Detail from JIRA
md5: d15a4e261b9a46cac7eb876d555e6767
duplicates:
Issue Description:
In Swift 4 (Xcode 9.1) I can't compare two optionals for equality (self.lineForms == item2.lineForms, where lineForms is [String]?). And indeed Equatable protocol only contains static func == (lhs: Self, rhs: Self) -> Bool, no optional versions. It's a bug, because https://github.com/apple/swift-evolution/blob/master/proposals/0121-remove-optional-comparison-operators.md clearly states "Variants of == and != which accept optional operands are still useful, and their results unsurprising, so they will remain.". And indeed, nil == nil is true, nil == non-nil is false (as well as non-nil == nil) and non-nil == non-nil should perform an actual comparison. I even can't create an extension to Equatable, because an error is shown that asks for at least one parameter of == to be of type Self (non-optional). Obviously, it's still possible to write (self.lineForms == nil && item2.lineForms == nil) || (self.lineForms ![](= nil && item2.lineForms )= nil && self.lineForms![]( == item2.lineForms)), but this doesn't look good and there's no reason to use this instead of just a single == comparison.
The text was updated successfully, but these errors were encountered: