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-1482] Compare arrays of optionals #44091

Closed
swift-ci opened this issue May 11, 2016 · 6 comments
Closed

[SR-1482] Compare arrays of optionals #44091

swift-ci opened this issue May 11, 2016 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1482
Radar None
Original Reporter svanimpe (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 7.3.1

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

md5: 8eb536899e9dcfae3cd643696fb4a68c

relates to:

  • SR-1535 No == overload exists for comparing optional arrays.
  • SR-2062 Optionals do not conform to CustomStringConvertible
  • SR-1997 Tuples with optional parameter aren't equatable

Issue Description:

The following code is inspired by code I wanted to write for a game of tic-tac-toe:

enum Player { case X, O }
var board: [Player?] = [.X, .X, .X, nil, nil, nil, nil, nil, nil]
let tripleX: [Player?] = [.X, .X, .X]
[0, 1, 2].map { board[$0] } == tripleX

This code does not compile as the operator == does not work for operands of type [Player?]. As a user of Swift, I would expect this to work, as the operator == does work with operands of type Player?.

@belkadan
Copy link
Contributor

This needs a feature called "conditional conformances", so that we know that Optional<T> is Equatable when T is Equatable. There are currently manual overloads for [T] and T?, but not for [T?].

@belkadan
Copy link
Contributor

@gribozavr, would we consider adding such an overload?

@gribozavr
Copy link
Collaborator

Given that it will work eventually, I don't see an issue with adding an overload now, as long as there is no fallout (e.g., from implicit conversions that get activated etc.)

Someone needs to champion this API for the evolution process.

@swift-ci
Copy link
Collaborator Author

Comment by David Liu (JIRA)

+1 any word on this?

@gribozavr
Copy link
Collaborator

Someone needs to either implement a missing feature in the compiler, or add special-case overloads of == and != to the library. The latter requires a swift-evolution proposal.

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

A year and a half later, conditional conformances now exists and Equatable is implemented for optionals and arrays, so this should work!

@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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants