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-1535] No == overload exists for comparing optional arrays. #44144

Closed
swift-ci opened this issue May 16, 2016 · 3 comments
Closed

[SR-1535] No == overload exists for comparing optional arrays. #44144

swift-ci opened this issue May 16, 2016 · 3 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-1535
Radar None
Original Reporter jaredsinclair (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: a2385dd9b41110cab90c3d9ba8328769

is duplicated by:

  • SR-6306 Return == and != for optionals

relates to:

  • SR-1482 Compare arrays of optionals
  • SR-1997 Tuples with optional parameter aren't equatable
  • SR-2284 Cannot invoke 'XCTAssertEqual' with an argument list of type '([Array], [[Int]])'
  • SR-3055 Switch statements fail to test optionals for equality

Issue Description:

There are overloads of == for optionals and for non-optional arrays, but there's no overload for comparing optional arrays. This seems like a small oversight but would be useful broadly.

For example, this will not compile:

let a: [Int] = [1,2]
let b: [Int]? = [2,3]
let c: [Int] = [1,2]
let q = (a == b) // Error: value not unwrapped...
let x = (a == c)

Providing an == overload for optional arrays would tie up the loose ends left between the existing overloads:

@warn_unused_result
public func ==<Element : Equatable>(lhs: [Element]?, rhs: [Element]?) -> Bool {    
    switch (lhs, rhs) {    
    case (.Some(let l), .Some(let r)):    
        return l == r    
    case (nil, nil):    
        return true    
    default:    
        return false    
    }    
}    
    
@warn_unused_result    
public func !=<Element : Equatable>(lhs: [Element]?, rhs: [Element]?) -> Bool {    
    return !(lhs == rhs)    
}

let a: [Int] = [1,2]
let b: [Int]? = [2,3]
let c: [Int] = [1,2]
let q = (a == b) // a is promoted to []?
let x = (a == c)

This change would be added to Arrays.swift.gyb, so it would need to be modified to conform to the .gyb syntax, and would thus also extend ArraySlice.

@belkadan
Copy link
Contributor

There's no overload for arrays of optionals either. It's unclear how far we actually want to go here.

@Dante-Broggi
Copy link
Contributor

I think this should have been closed after SE-0143 (Conditional Conformances) was implemented in Swift 4.2

@belkadan
Copy link
Contributor

Agreed!

@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