Skip to content

Commit 00d8774

Browse files
committed
[Sema] Upgrade tuple shuffle warning to error in future lang mode
This has been deprecated for a while now, flip it to an error for a future language mode.
1 parent 2434781 commit 00d8774

File tree

9 files changed

+45
-20
lines changed

9 files changed

+45
-20
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7833,8 +7833,13 @@ ERROR(result_builder_buildpartialblock_accumulated_not_accessible,none,
78337833
// MARK: Tuple Shuffle Diagnostics
78347834
//------------------------------------------------------------------------------
78357835

7836+
ERROR(reordering_tuple_shuffle,none,
7837+
"cannot implicitly reorder tuple elements from '%0' to '%1'",
7838+
(StringRef, StringRef))
7839+
78367840
WARNING(warn_reordering_tuple_shuffle_deprecated,Deprecation,
7837-
"implicit reordering of tuple elements from '%0' to '%1' is deprecated",
7841+
"implicit reordering of tuple elements from '%0' to '%1' is deprecated"
7842+
"; this will be an error in a future Swift language mode",
78387843
(StringRef, StringRef))
78397844

78407845
//------------------------------------------------------------------------------

lib/Sema/CSApply.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,9 +5867,15 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
58675867
SmallString<16> toLabelStr;
58685868
concatLabels(labels, toLabelStr);
58695869

5870-
ctx.Diags.diagnose(expr->getLoc(),
5871-
diag::warn_reordering_tuple_shuffle_deprecated,
5872-
fromLabelStr, toLabelStr);
5870+
using namespace version;
5871+
if (ctx.isSwiftVersionAtLeast(Version::getFutureMajorLanguageVersion())) {
5872+
ctx.Diags.diagnose(expr->getLoc(), diag::reordering_tuple_shuffle,
5873+
fromLabelStr, toLabelStr);
5874+
} else {
5875+
ctx.Diags.diagnose(expr->getLoc(),
5876+
diag::warn_reordering_tuple_shuffle_deprecated,
5877+
fromLabelStr, toLabelStr);
5878+
}
58735879
}
58745880

58755881
// Create the result tuple, written in terms of the destructured
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 5
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
25

36
func consume<T>(_ x: T) {} // Suppress unused variable warnings
47

58
func shuffle_through_initialization() {
69
let a = (x: 1, y: 2)
710
let b: (y: Int, x: Int)
8-
b = a // expected-warning {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated}}
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:'}}
914
consume(b)
1015
}
1116

1217
func shuffle_raw_label(_ t: (`a b`: Int, `c d`: Int)) {
1318
let _: (`c d`: Int, `a b`: Int) = t
14-
// expected-warning@-1 {{implicit reordering of tuple elements from '`a b`:`c d`:' to '`c d`:`a b`:' is deprecated}}
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`:'}}
1521
}
1622

1723
func shuffle_through_destructuring() {
1824
let a = (x: 1, y: 2)
19-
let (y: b, x: c) = a // expected-warning {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated}}
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:'}}
2028
consume((b, c))
2129
}
2230

2331
func shuffle_through_call() {
2432
func foo(_ : (x: Int, y: Int)) {}
25-
foo((y: 5, x: 10)) // expected-warning {{implicit reordering of tuple elements from 'y:x:' to 'x:y:' is deprecated}}
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:'}}
2636
}
2737

2838
func shuffle_through_cast() {
29-
let x = ((a: Int(), b: Int()) as (b: Int, a: Int)).0 // expected-warning {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
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:'}}
3042

3143
// Ah, the famous double-shuffle
3244
let (c1, (c2, c3)): (c: Int, (b: Int, a: Int)) = ((a: Int(), b: Int()), c: Int())
33-
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
34-
// expected-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated}}
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:_:'}}
3549
consume((x, c1, c2, c3))
3650
}

test/Parse/omit_return.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func ff_implicitInjectIntoOptionalExpr(_ int: Int) -> Int? {
474474
}
475475

476476
func ff_implicitTupleShuffle(_ input: (one: Int, two: Int)) -> (two: Int, one: Int) {
477-
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated}}
477+
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated; this will be an error in a future Swift language mode}}
478478
}
479479

480480
func ff_implicitCollectionUpcast(_ derived: [Derived]) -> [Base] {

test/Parse/omit_return_ifdecl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func ff_implicitInjectIntoOptionalExpr(_ int: Int) -> Int? {
676676

677677
func ff_implicitTupleShuffle(_ input: (one: Int, two: Int)) -> (two: Int, one: Int) {
678678
#if true
679-
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated}}
679+
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated; this will be an error in a future Swift language mode}}
680680
#endif
681681
}
682682

test/Sema/diag_unowned_immediate_deallocation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ func testGenericWeakClassDiag() {
452452
// The diagnostic doesn't currently support tuple shuffles.
453453
func testDontDiagnoseThroughTupleShuffles() {
454454
unowned let (c1, (c2, c3)): (c: C, (b: C, a: C)) = ((a: D(), b: C()), c: D())
455-
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
456-
// expected-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated}}
455+
// expected-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}}
456+
// expected-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated; this will be an error in a future Swift language mode}}
457457
unowned let c4 = ((a: C(), b: C()) as (b: C, a: C)).0
458-
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
458+
// expected-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}}
459459

460460
_ = c1; _ = c2; _ = c3; _ = c4
461461
}

test/decl/func/operator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var f2 : (Int) -> Int = (+-+)
155155
var f3 : (inout Int) -> Int = (-+-) // expected-error{{ambiguous use of operator '-+-'}}
156156
var f4 : (inout Int, Int) -> Int = (+-+=)
157157
var r5 : (a : (Int, Int) -> Int, b : (Int, Int) -> Int) = (+, -)
158-
var r6 : (a : (Int, Int) -> Int, b : (Int, Int) -> Int) = (b : +, a : -) // expected-warning {{implicit reordering of tuple elements from 'b:a:' to 'a:b:' is deprecated}}
158+
var r6 : (a : (Int, Int) -> Int, b : (Int, Int) -> Int) = (b : +, a : -) // expected-warning {{implicit reordering of tuple elements from 'b:a:' to 'a:b:' is deprecated; this will be an error in a future Swift language mode}}
159159

160160
struct f6_S {
161161
subscript(op : (Int, Int) -> Int) -> Int {

test/expr/closure/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func funcdecl5(_ a: Int, _ y: Int) {
5656
var b = a.1+a.f
5757

5858
// Tuple expressions with named elements.
59-
var i : (y : Int, x : Int) = (x : 42, y : 11) // expected-warning {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated}}
59+
var i : (y : Int, x : Int) = (x : 42, y : 11) // expected-warning {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated; this will be an error in a future Swift language mode}}
6060
funcdecl1(123, 444)
6161

6262
// Calls.

test/expr/expressions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func test5() {
194194

195195

196196
let c: (a: Int, b: Int) = (1,2)
197-
let _: (b: Int, a: Int) = c // expected-warning {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
197+
let _: (b: Int, a: Int) = c // expected-warning {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated; this will be an error in a future Swift language mode}}
198198
}
199199

200200

0 commit comments

Comments
 (0)