Files
swift-mirror/test/Constraints/tuple_shuffle.swift
Robert Widmann a9e871a0b1 [Sema] Warn About Tuple Shuffles
Emit a warning that tuple shuffling is deprecated across the board. In
the future, we should try to unshuffle these expressions where we can,
but that's a diagnostic improvement for another day.

See also https://forums.swift.org/t/deprecating-tuple-shuffles-round-2/16884/30
2020-02-13 17:29:03 -08:00

32 lines
1.1 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 5
func consume<T>(_ x: T) {} // Suppress unused variable warnings
func shuffle_through_initialization() {
let a = (x: 1, y: 2)
let b: (y: Int, x: Int)
b = a // expected-warning {{expression shuffles the elements of this tuple}}
consume(b)
}
func shuffle_through_destructuring() {
let a = (x: 1, y: 2)
let (y: b, x: c) = a // expected-warning {{expression shuffles the elements of this tuple}}
consume((b, c))
}
func shuffle_through_call() {
func foo(_ : (x: Int, y: Int)) {}
foo((y: 5, x: 10)) // expected-warning {{expression shuffles the elements of this tuple}}
}
func shuffle_through_cast() {
let x = ((a: Int(), b: Int()) as (b: Int, a: Int)).0 // expected-warning {{expression shuffles the elements of this tuple}}
// Ah, the famous double-shuffle
let (c1, (c2, c3)): (c: Int, (b: Int, a: Int)) = ((a: Int(), b: Int()), c: Int())
// expected-warning@-1 {{expression shuffles the elements of this tuple}}
// expected-warning@-2 {{expression shuffles the elements of this tuple}}
consume((x, c1, c2, c3))
}