Redeclaration of named tuple members

I think it is somehow more desirable than what you ask for (blindly allow conversion between any tuples with matching element types disregarding their labels) because it would remove the use of / need for labels, at least from a type safety point of view.

I forgot to mention another subtle side of the current behavior:

func test() {
    var a = (x: 1, y: 2)
    var b = (y: 3, x: 4)
    
    a = b // OK (perhaps surprisingly)
    print(a) // (x: 4, y: 3)
    b = a // OK (perhaps surprisingly)
    print(b) // (y: 3, x: 4)
    
    print(a == b) // false (perhaps surprising that two values of different type can be checked for equality?)
    print(a == b as (x: Int, y: Int)) // true
    print(type(of: a) == type(of: b)) // false
}
test()

I don't think the above is desirable behavior and it will not compile if tuple shuffling is deprecated. But if what you ask for would be allowed, then I guess the above would have to compile, and the result would probably be different, I guess it would be like this:

// NOTE: Speculated alternative behavior if label-ignoring conversion was allowed:
func test() {
    var a = (x: 1, y: 2)
    var b = (y: 3, x: 4)
    
    a = b // OK
    print(a) // (x: 3, y: 4)
    b = a // OK
    print(b) // (y: 3, x: 4)
    
    print(a == b) // true
    print(a == b as (x: Int, y: Int)) // true
    print(type(of: a) == type(of: b)) // true ... I guess ... ?
}
test()

Which would arguably be even stranger than the current behavior. Also, would the type of a and b be different or the same?

I think the current behavior + deprecated tuple shuffles makes most sense, all aspects (that I can think of) taken into consideration.

2 Likes