mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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.
This commit is contained in:
@@ -7833,8 +7833,13 @@ ERROR(result_builder_buildpartialblock_accumulated_not_accessible,none,
|
||||
// MARK: Tuple Shuffle Diagnostics
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ERROR(reordering_tuple_shuffle,none,
|
||||
"cannot implicitly reorder tuple elements from '%0' to '%1'",
|
||||
(StringRef, StringRef))
|
||||
|
||||
WARNING(warn_reordering_tuple_shuffle_deprecated,Deprecation,
|
||||
"implicit reordering of tuple elements from '%0' to '%1' is deprecated",
|
||||
"implicit reordering of tuple elements from '%0' to '%1' is deprecated"
|
||||
"; this will be an error in a future Swift language mode",
|
||||
(StringRef, StringRef))
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -5867,9 +5867,15 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
|
||||
SmallString<16> toLabelStr;
|
||||
concatLabels(labels, toLabelStr);
|
||||
|
||||
ctx.Diags.diagnose(expr->getLoc(),
|
||||
diag::warn_reordering_tuple_shuffle_deprecated,
|
||||
fromLabelStr, toLabelStr);
|
||||
using namespace version;
|
||||
if (ctx.isSwiftVersionAtLeast(Version::getFutureMajorLanguageVersion())) {
|
||||
ctx.Diags.diagnose(expr->getLoc(), diag::reordering_tuple_shuffle,
|
||||
fromLabelStr, toLabelStr);
|
||||
} else {
|
||||
ctx.Diags.diagnose(expr->getLoc(),
|
||||
diag::warn_reordering_tuple_shuffle_deprecated,
|
||||
fromLabelStr, toLabelStr);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the result tuple, written in terms of the destructured
|
||||
|
||||
@@ -1,36 +1,50 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 5
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift6-
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 7 -verify-additional-prefix swift7-
|
||||
|
||||
// REQUIRES: swift7
|
||||
|
||||
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 {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated}}
|
||||
b = a
|
||||
// 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}}
|
||||
// expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'x:y:' to 'y:x:'}}
|
||||
consume(b)
|
||||
}
|
||||
|
||||
func shuffle_raw_label(_ t: (`a b`: Int, `c d`: Int)) {
|
||||
let _: (`c d`: Int, `a b`: Int) = t
|
||||
// expected-warning@-1 {{implicit reordering of tuple elements from '`a b`:`c d`:' to '`c d`:`a b`:' is deprecated}}
|
||||
// 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}}
|
||||
// expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from '`a b`:`c d`:' to '`c d`:`a b`:'}}
|
||||
}
|
||||
|
||||
func shuffle_through_destructuring() {
|
||||
let a = (x: 1, y: 2)
|
||||
let (y: b, x: c) = a // expected-warning {{implicit reordering of tuple elements from 'x:y:' to 'y:x:' is deprecated}}
|
||||
let (y: b, x: c) = a
|
||||
// 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}}
|
||||
// expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'x:y:' to 'y:x:'}}
|
||||
consume((b, c))
|
||||
}
|
||||
|
||||
func shuffle_through_call() {
|
||||
func foo(_ : (x: Int, y: Int)) {}
|
||||
foo((y: 5, x: 10)) // expected-warning {{implicit reordering of tuple elements from 'y:x:' to 'x:y:' is deprecated}}
|
||||
foo((y: 5, x: 10))
|
||||
// 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}}
|
||||
// expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'y:x:' to 'x:y:'}}
|
||||
}
|
||||
|
||||
func shuffle_through_cast() {
|
||||
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}}
|
||||
let x = ((a: Int(), b: Int()) as (b: Int, a: Int)).0
|
||||
// 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}}
|
||||
// expected-swift7-error@-2 {{cannot implicitly reorder tuple elements from 'a:b:' to 'b:a:'}}
|
||||
|
||||
// Ah, the famous double-shuffle
|
||||
let (c1, (c2, c3)): (c: Int, (b: Int, a: Int)) = ((a: Int(), b: Int()), c: Int())
|
||||
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
|
||||
// expected-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated}}
|
||||
// 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}}
|
||||
// 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}}
|
||||
// expected-swift7-error@-3 {{cannot implicitly reorder tuple elements from 'a:b:' to 'b:a:'}}
|
||||
// expected-swift7-error@-4 {{cannot implicitly reorder tuple elements from '_:c:' to 'c:_:'}}
|
||||
consume((x, c1, c2, c3))
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ func ff_implicitInjectIntoOptionalExpr(_ int: Int) -> Int? {
|
||||
}
|
||||
|
||||
func ff_implicitTupleShuffle(_ input: (one: Int, two: Int)) -> (two: Int, one: Int) {
|
||||
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated}}
|
||||
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}}
|
||||
}
|
||||
|
||||
func ff_implicitCollectionUpcast(_ derived: [Derived]) -> [Base] {
|
||||
|
||||
@@ -676,7 +676,7 @@ func ff_implicitInjectIntoOptionalExpr(_ int: Int) -> Int? {
|
||||
|
||||
func ff_implicitTupleShuffle(_ input: (one: Int, two: Int)) -> (two: Int, one: Int) {
|
||||
#if true
|
||||
input // expected-warning {{implicit reordering of tuple elements from 'one:two:' to 'two:one:' is deprecated}}
|
||||
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}}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -452,10 +452,10 @@ func testGenericWeakClassDiag() {
|
||||
// The diagnostic doesn't currently support tuple shuffles.
|
||||
func testDontDiagnoseThroughTupleShuffles() {
|
||||
unowned let (c1, (c2, c3)): (c: C, (b: C, a: C)) = ((a: D(), b: C()), c: D())
|
||||
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
|
||||
// expected-warning@-2 {{implicit reordering of tuple elements from '_:c:' to 'c:_:' is deprecated}}
|
||||
// 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}}
|
||||
// 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}}
|
||||
unowned let c4 = ((a: C(), b: C()) as (b: C, a: C)).0
|
||||
// expected-warning@-1 {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
|
||||
// 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}}
|
||||
|
||||
_ = c1; _ = c2; _ = c3; _ = c4
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ var f2 : (Int) -> Int = (+-+)
|
||||
var f3 : (inout Int) -> Int = (-+-) // expected-error{{ambiguous use of operator '-+-'}}
|
||||
var f4 : (inout Int, Int) -> Int = (+-+=)
|
||||
var r5 : (a : (Int, Int) -> Int, b : (Int, Int) -> Int) = (+, -)
|
||||
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}}
|
||||
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}}
|
||||
|
||||
struct f6_S {
|
||||
subscript(op : (Int, Int) -> Int) -> Int {
|
||||
|
||||
@@ -56,7 +56,7 @@ func funcdecl5(_ a: Int, _ y: Int) {
|
||||
var b = a.1+a.f
|
||||
|
||||
// Tuple expressions with named elements.
|
||||
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}}
|
||||
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}}
|
||||
funcdecl1(123, 444)
|
||||
|
||||
// Calls.
|
||||
|
||||
@@ -194,7 +194,7 @@ func test5() {
|
||||
|
||||
|
||||
let c: (a: Int, b: Int) = (1,2)
|
||||
let _: (b: Int, a: Int) = c // expected-warning {{implicit reordering of tuple elements from 'a:b:' to 'b:a:' is deprecated}}
|
||||
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}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user