Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6306] Return == and != for optionals #48856

Closed
swift-ci opened this issue Nov 6, 2017 · 1 comment
Closed

[SR-6306] Return == and != for optionals #48856

swift-ci opened this issue Nov 6, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 6, 2017

Previous ID SR-6306
Radar None
Original Reporter Shuricksoft (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: d15a4e261b9a46cac7eb876d555e6767

duplicates:

  • 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.

@belkadan
Copy link
Contributor

belkadan commented Nov 6, 2017

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.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants