Skip to content

Use conditional conformances to implement Equatable for Optional, Array, and Dictionary #13046

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

Merged

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Nov 22, 2017

Introduce conditional conformances to Equatable for Optional, Array, and Dictionary.

Fixes rdar://problem/21504479, rdar://problem/32035512, and rdar://problem/17924430.

@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor force-pushed the conditional-conformance-equatable branch from 72592e4 to c82ff04 Compare November 22, 2017 06:56
@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - b95a71c453b74ac7f1b1ff32cdf2bf32c3018b5d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - b95a71c453b74ac7f1b1ff32cdf2bf32c3018b5d

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

DougGregor commented Nov 24, 2017

Ah, the source compatibility failure in Kickstarter is real, and caused by the XCTest changes:

/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/Kickstarter-ReactiveExtensions/ReactiveExtensionsTests/TestHelpers/XCTAssert-Extensions.swift:5:15: note: found this candidate
internal func XCTAssertEqual<T: Equatable>(_ expression1: @autoclosure () -> [[T]],
              ^
XCTest.XCTAssertEqual:1:13: note: found this candidate
public func XCTAssertEqual<T>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line) where T : Equatable
            ^

I've captured the overloading issue in https://bugs.swift.org/browse/SR-6472.

@DougGregor DougGregor changed the title [DO NOT MERGE] Use conditional conformances to implement Equatable for Optional, Array, Set and Dictionary [DO NOT MERGE] Use conditional conformances to implement Equatable for Optional, Array, and Dictionary Nov 28, 2017
@DougGregor DougGregor force-pushed the conditional-conformance-equatable branch from c82ff04 to 5becd92 Compare November 28, 2017 01:38
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

But UPASS’s. Ready to go in pending core team approval

@DougGregor DougGregor added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Nov 28, 2017
huonw and others added 4 commits November 27, 2017 21:09
XCTest had XCAssert(Not)Equal overloads for optionals, arrays
(including contiguous arrays and array slices), and dictionaries to
work around the lack of conditional conformances to Equatable. Now
that we have the latter, remove the former.

Fixes rdar://problem/17924430.
@DougGregor DougGregor force-pushed the conditional-conformance-equatable branch from 5becd92 to 887ad4a Compare November 28, 2017 05:18
@DougGregor
Copy link
Member Author

Rebased and ChangeLog'd.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor changed the title [DO NOT MERGE] Use conditional conformances to implement Equatable for Optional, Array, and Dictionary Use conditional conformances to implement Equatable for Optional, Array, and Dictionary Nov 28, 2017
@DougGregor DougGregor merged commit fa1d07c into swiftlang:master Nov 28, 2017
@DougGregor DougGregor deleted the conditional-conformance-equatable branch November 28, 2017 18:05
@frogcjn
Copy link

frogcjn commented Dec 2, 2017

Equatable for two dimension array is still not working (e.g. [[1]] == [[1]])

I used the swift-4.1-DEVELOPMENT-SNAPSHOT-2017-11-30-a-osx to test:

Welcome to Apple Swift version 4.1-dev (LLVM 05fee6ff60, Clang f0e38d2044, Swift a1441d34f7). Type :help for assistance.
  1> [[1]] == [[1]]
error: repl.swift:1:7: error: binary operator '==' cannot be applied to two '[[Int]]' operands
[[1]] == [[1]]
~~~~~ ^  ~~~~~

repl.swift:1:7: note: overloads for '==' exist with these partially matching parameter lists: (Any.Type?, Any.Type?), ((), ()), (Bool, Bool), (Character, Character), (Character.UnicodeScalarView.Index, Character.UnicodeScalarView.Index), (CodingUserInfoKey, CodingUserInfoKey), (OpaquePointer, OpaquePointer), (AnyHashable, AnyHashable), (UInt8, UInt8), (Int8, Int8), (UInt16, UInt16), (Int16, Int16), (UInt32, UInt32), (Int32, Int32), (UInt64, UInt64), (Int64, Int64), (UInt, UInt), (Int, Int), (AnyKeyPath, AnyKeyPath), (Unicode.Scalar, Unicode.Scalar), (ObjectIdentifier, ObjectIdentifier), (String, String), (String.Index, String.Index), (UnsafeMutableRawPointer, UnsafeMutableRawPointer), (UnsafeRawPointer, UnsafeRawPointer), (UnicodeDecodingResult, UnicodeDecodingResult), (_SwiftNSOperatingSystemVersion, _SwiftNSOperatingSystemVersion), (AnyIndex, AnyIndex), (ContiguousArray<Element>, ContiguousArray<Element>), (ArraySlice<Element>, ArraySlice<Element>), (T?, T?), (T?, _OptionalNilComparisonType), (_OptionalNilComparisonType, T?), ((A, B), (A, B)), ((A, B, C), (A, B, C)), ((A, B, C, D), (A, B, C, D)), ((A, B, C, D, E), (A, B, C, D, E)), ((A, B, C, D, E, F), (A, B, C, D, E, F)), (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>), (ClosedRangeIndex<Bound>, ClosedRangeIndex<Bound>), (DoubleWidth<Base>, DoubleWidth<Base>), (DoubleWidth<Base>.Words.Index, DoubleWidth<Base>.Words.Index), (LazyDropWhileIndex<Base>, LazyDropWhileIndex<Base>), (EmptyCollection<Element>, EmptyCollection<Element>), (FlattenCollectionIndex<BaseElements>, FlattenCollectionIndex<BaseElements>), (FlattenBidirectionalCollectionIndex<BaseElements>, FlattenBidirectionalCollectionIndex<BaseElements>), (Set<Element>, Set<Element>), (Dictionary<Key, Value>.Keys, Dictionary<Key, Value>.Keys), ([Key : Value], [Key : Value]), (Set<Element>.Index, Set<Element>.Index), (Dictionary<Key, Value>.Index, Dictionary<Key, Value>.Index), (ManagedBufferPointer<Header, Element>, ManagedBufferPointer<Header, Element>), (LazyPrefixWhileIndex<Base>, LazyPrefixWhileIndex<Base>), (Range<Bound>, Range<Bound>), (CountableRange<Bound>, CountableRange<Bound>), (ClosedRange<Bound>, ClosedRange<Bound>), (CountableClosedRange<Bound>, CountableClosedRange<Bound>), (ReversedIndex<Base>, ReversedIndex<Base>), (ReversedRandomAccessIndex<Base>, ReversedRandomAccessIndex<Base>), (_UIntBuffer<Storage, Element>.Index, _UIntBuffer<Storage, Element>.Index), (UnsafeMutablePointer<Pointee>, UnsafeMutablePointer<Pointee>), (UnsafePointer<Pointee>, UnsafePointer<Pointee>), (_ValidUTF8Buffer<Storage>.Index, _ValidUTF8Buffer<Storage>.Index), (Self, Other), (Self, R)
[[1]] == [[1]]
      ^

@DougGregor
Copy link
Member Author

You'll need a snapshot from master, or wait until we get a snapshot from a rebranched Swift 4.1 (which will be available in a day or two), to get this feature.

@AnthonyLatsis
Copy link
Collaborator

Proposal: SE-0143.

@AnthonyLatsis AnthonyLatsis added swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented and removed swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review labels Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants