Skip to content

Commit e1a5a81

Browse files
author
Arjun Nayini
committed
[stdlib] 0-ary tuples should be equatable
Add an == method for comparing two empty tuples. Resolves: SR-4172 (https://bugs.swift.org/browse/SR-4172)
1 parent f6b0542 commit e1a5a81

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

stdlib/public/core/Tuple.swift.gyb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ comparableOperators = [
2323

2424
}%
2525

26+
/// Two tuples each of arity 0 are equal
27+
/// - Parameters:
28+
/// - lhs: An empty tuple.
29+
/// - rhs: An empty tuple.
30+
public func ==(lhs: (), rhs: ()) -> Bool {
31+
return true
32+
}
33+
2634
% for arity in range(2,7):
2735
% typeParams = [chr(ord("A") + i) for i in range(arity)]
2836
% tupleT = "({})".format(",".join(typeParams))

test/stdlib/Tuple.swift.gyb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ TupleTestSuite.test("Tuple/equality") {
5858

5959
TupleTestSuite.test("Tuple/equality/sanity-check") {
6060
// sanity check all arities
61+
62+
// 0-ary tuples should be equal
63+
expectTrue(() == ())
6164
% for arity in range(2, maxArity + 1):
6265
% a = str(tuple(range(1, arity + 1)))
6366
% b = "({}, 0)".format(", ".join([str(i) for i in range(1, arity)]))

0 commit comments

Comments
 (0)