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-12112] Accepts Invalid, Tuple labels with different order are considered the same. #54548

Closed
jepers opened this issue Jan 30, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@jepers
Copy link

jepers commented Jan 30, 2020

Previous ID SR-12112
Radar rdar://problem/59132831
Original Reporter @jepers
Type Bug
Status Resolved
Resolution Invalid
Environment

Default toolchain of Xcode 11.3.1 (11C504)

and

Swift Development Snapshot 2020-01-21 (a)

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

md5: 0cf428a84023959ac294b148f75086f4

Issue Description:

( From this post: https://forums.swift.org/t/tuples-conform-to-equatable/32559/39 )

var a = (x: 2, y: 4)
var b = (y: 4, x: 2)

print(a.x == b.x && a.y == b.y) // true
print(     a     ==     b     ) // false

a = b         // <-- Assigning despite `a` and `b` having different labels.
print(a == b) // false
b = a         // <-- Assigning despite `b` and `a` having different labels.
print(a == b) // false 

Expected behavior: The labels of `a` should be considered different from the labels of `b`, because tuple element order matters, and thus the assignments should be invalid and the error should be the same as if eg `b` had been `(p: 4, q: 2)`.

Observed behavior: The labels of `a` are considered the same as the labels of `b`, as if tuple element order didn't matter, and thus the compiler accepts invalid code.

@beccadax
Copy link
Contributor

beccadax commented Feb 4, 2020

@swift-ci create

@slavapestov
Copy link
Member

Tuple element order matters, but there is an implicit conversion between tuple types where the labels are identical but in a different order.

There are also implicit conversions between tuple types with labels and the same type without labels, and vice versa.

So this is working as intended. == is overloaded for unlabeled tuples of various arity, so 'a == b' is false because 'a' is converted into (2, 4) and 'b' is converted into (4, 2).

However, a = b succeeds because of the implicit conversion between (x: Int, y: Int) and (y: Int, x: Int).

@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.
Projects
None yet
Development

No branches or pull requests

3 participants