|
1 | | -// RUN: %target-typecheck-verify-swift -swift-version 5 |
2 | | - |
3 | | - func consume<T>(_ x: T) {} // Suppress unused variable warnings |
4 | | - |
5 | | - func shuffle_through_initialization() { |
6 | | - let a = (x: 1, y: 2) |
7 | | - let b: (y: Int, x: Int) |
8 | | - b = a // expected-warning {{expression shuffles the elements of this tuple}} |
9 | | - consume(b) |
10 | | - } |
11 | | - |
12 | | - func shuffle_through_destructuring() { |
13 | | - let a = (x: 1, y: 2) |
14 | | - let (y: b, x: c) = a // expected-warning {{expression shuffles the elements of this tuple}} |
15 | | - consume((b, c)) |
16 | | - } |
17 | | - |
18 | | - func shuffle_through_call() { |
19 | | - func foo(_ : (x: Int, y: Int)) {} |
20 | | - foo((y: 5, x: 10)) // expected-warning {{expression shuffles the elements of this tuple}} |
21 | | - } |
22 | | - |
23 | | - func shuffle_through_cast() { |
24 | | - let x = ((a: Int(), b: Int()) as (b: Int, a: Int)).0 // expected-warning {{expression shuffles the elements of this tuple}} |
25 | | - |
26 | | - // Ah, the famous double-shuffle |
27 | | - let (c1, (c2, c3)): (c: Int, (b: Int, a: Int)) = ((a: Int(), b: Int()), c: Int()) |
28 | | - // expected-warning@-1 {{expression shuffles the elements of this tuple}} |
29 | | - // expected-warning@-2 {{expression shuffles the elements of this tuple}} |
30 | | - consume((x, c1, c2, c3)) |
31 | | - } |
| 1 | +// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift6- |
| 2 | +// RUN: %target-typecheck-verify-swift -swift-version 7 -verify-additional-prefix swift7- |
| 3 | + |
| 4 | +// REQUIRES: swift7 |
| 5 | + |
| 6 | +func consume<T>(_ x: T) {} // Suppress unused variable warnings |
| 7 | + |
| 8 | +func shuffle_through_initialization() { |
| 9 | + let a = (x: 1, y: 2) |
| 10 | + let b: (y: Int, x: Int) |
| 11 | + b = a |
| 12 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated; this will be an error in a future Swift language mode}} |
| 13 | + // expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'x:y:' to 'y:x:'}} |
| 14 | + consume(b) |
| 15 | +} |
| 16 | + |
| 17 | +func shuffle_raw_label(_ t: (`a b`: Int, `c d`: Int)) { |
| 18 | + let _: (`c d`: Int, `a b`: Int) = t |
| 19 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from '`a b`:`c d`:' to '`c d`:`a b`:' is deprecated; this will be an error in a future Swift language mode}} |
| 20 | + // expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from '`a b`:`c d`:' to '`c d`:`a b`:'}} |
| 21 | +} |
| 22 | + |
| 23 | +func shuffle_through_destructuring() { |
| 24 | + let a = (x: 1, y: 2) |
| 25 | + let (y: b, x: c) = a |
| 26 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated; this will be an error in a future Swift language mode}} |
| 27 | + // expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'x:y:' to 'y:x:'}} |
| 28 | + consume((b, c)) |
| 29 | +} |
| 30 | + |
| 31 | +func shuffle_through_call() { |
| 32 | + func foo(_ : (x: Int, y: Int)) {} |
| 33 | + foo((y: 5, x: 10)) |
| 34 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from 'y:x:' to 'x:y:' is deprecated; this will be an error in a future Swift language mode}} |
| 35 | + // expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'y:x:' to 'x:y:'}} |
| 36 | +} |
| 37 | + |
| 38 | +func shuffle_through_cast() { |
| 39 | + let x = ((a: Int(), b: Int()) as (b: Int, a: Int)).0 |
| 40 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated; this will be an error in a future Swift language mode}} |
| 41 | + // expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'a:b:' to 'b:a:'}} |
| 42 | + |
| 43 | + // Ah, the famous double-shuffle |
| 44 | + let (c1, (c2, c3)): (c: Int, (b: Int, a: Int)) = ((a: Int(), b: Int()), c: Int()) |
| 45 | + // expected-swift6-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated; this will be an error in a future Swift language mode}} |
| 46 | + // expected-swift6-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated; this will be an error in a future Swift language mode}} |
| 47 | + // expected-swift7-error@-3 {{cannot implicitly reorder tuple elements from 'a:b:' to 'b:a:'}} |
| 48 | + // expected-swift7-error@-4 {{cannot implicitly reorder tuple elements from '_:c:' to 'c:_:'}} |
| 49 | + consume((x, c1, c2, c3)) |
| 50 | +} |
0 commit comments