Skip to content

Commit 5be9175

Browse files
committed
[SR-4005] Allow heterogenous comparisons in elementsEqual
When a user is supplying a predicate to compare the type equivalence isn’t required
1 parent 890dbf1 commit 5be9175

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

stdlib/public/core/SequenceAlgorithms.swift.gyb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,14 @@ ${equivalenceExplanation}
358358
public func elementsEqual<OtherSequence>(
359359
_ other: OtherSequence${"," if preds else ""}
360360
% if preds:
361-
by areEquivalent: (${GElement}, ${GElement}) throws -> Bool
361+
by areEquivalent: (${GElement}, OtherSequence.${GElement}) throws -> Bool
362362
% end
363363
) ${rethrows_}-> Bool
364364
where
365-
OtherSequence: Sequence,
365+
OtherSequence: Sequence${" {" if preds else ","}
366+
% if not preds:
366367
OtherSequence.${GElement} == ${GElement} {
368+
% end
367369
368370
var iter1 = self.makeIterator()
369371
var iter2 = other.makeIterator()

test/IDE/complete_from_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func testArchetypeReplacement3 (_ a : [Int]) {
172172
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropLast({#(n): Int#})[#ArraySlice<Int>#]
173173
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropFirst({#(n): Int#})[#AnySequence<Int>#]
174174
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: prefix({#(maxLength): Int#})[#AnySequence<Int>#]
175-
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#by: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
175+
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#by: (Int, IteratorProtocol.Element) throws -> Bool##(Int, IteratorProtocol.Element) throws -> Bool#})[' rethrows'][#Bool#]
176176

177177

178178
protocol P2 {

test/api-digester/source-stability.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ Func ReversedRandomAccessCollection.index(_:offsetBy:) has return type change fr
318318
Func ReversedRandomAccessCollection.index(_:offsetBy:limitedBy:) has return type change from ReversedRandomAccessIndex<Base>? to ReversedRandomAccessCollection.Index?
319319
Func ReversedRandomAccessCollection.index(after:) has return type change from ReversedRandomAccessIndex<Base> to ReversedRandomAccessCollection.Index
320320
Func ReversedRandomAccessCollection.index(before:) has return type change from ReversedRandomAccessIndex<Base> to ReversedRandomAccessCollection.Index
321+
Func Sequence.elementsEqual(_:by:) has 2nd parameter type change from (Self.Iterator.Element, Self.Iterator.Element) throws -> Bool to (Self.Iterator.Element, OtherSequence.Iterator.Element) throws -> Bool
321322
Func Set.formSymmetricDifference(_:) has parameter 0 type change from Set<Element> to Set<Set.Element>
322323
Func Set.index(after:) has return type change from SetIndex<Element> to Set<Element>.Index
323324
Func Set.index(of:) has return type change from SetIndex<Element>? to Set<Element>.Index?

0 commit comments

Comments
 (0)