[CS] Upgrade tuple label mismatch warning to error for future lang mode

I missed upgrading this to an error for Swift 6 mode, let's upgrade it
to an error for a future language mode. It's important we reject these
cases since we're otherwise allowing subtyping to be a weaker constraint
than conversion.
This commit is contained in:
Hamish Knight
2025-10-29 15:14:23 +00:00
parent 1f9300319b
commit 1781faba1a
6 changed files with 43 additions and 28 deletions

View File

@@ -342,27 +342,6 @@ optionalTuple = (bignum, 1) // expected-error {{cannot assign value of type '(In
optionalTuple = optionalTuple2 // expected-error {{cannot assign value of type '(Int64, Int)?' to type '(Int, Int)?'}}
// expected-note@-1 {{arguments to generic parameter 'Wrapped' ('(Int64, Int)' and '(Int, Int)') are expected to be equal}}
func testTupleLabelMismatchFuncConversion(fn1: @escaping ((x: Int, y: Int)) -> Void,
fn2: @escaping () -> (x: Int, Int)) {
// Warn on mismatches
let _: ((a: Int, b: Int)) -> Void = fn1 // expected-warning {{tuple conversion from '(a: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
let _: ((x: Int, b: Int)) -> Void = fn1 // expected-warning {{tuple conversion from '(x: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
let _: () -> (y: Int, Int) = fn2 // expected-warning {{tuple conversion from '(x: Int, Int)' to '(y: Int, Int)' mismatches labels}}
let _: () -> (y: Int, k: Int) = fn2 // expected-warning {{tuple conversion from '(x: Int, Int)' to '(y: Int, k: Int)' mismatches labels}}
// Attempting to shuffle has always been illegal here
let _: () -> (y: Int, x: Int) = fn2 // expected-error {{cannot convert value of type '() -> (x: Int, Int)' to specified type '() -> (y: Int, x: Int)'}}
// Losing labels is okay though.
let _: () -> (Int, Int) = fn2
// Gaining labels also okay.
let _: ((x: Int, Int)) -> Void = fn1
let _: () -> (x: Int, y: Int) = fn2
let _: () -> (Int, y: Int) = fn2
}
func testTupleLabelMismatchKeyPath() {
// FIXME: The warning should be upgraded to an error for key paths.
let _: KeyPath<(x: Int, y: Int), Int> = \(a: Int, b: Int).x

View File

@@ -0,0 +1,33 @@
// RUN: %target-typecheck-verify-swift -language-mode 6 -verify-additional-prefix swift6-
// RUN: %target-typecheck-verify-swift -language-mode 7 -verify-additional-prefix swift7-
// REQUIRES: swift7
func testTupleLabelMismatchFuncConversion(fn1: @escaping ((x: Int, y: Int)) -> Void,
fn2: @escaping () -> (x: Int, Int)) {
// Warn on mismatches in Swift 6, upgrading to an error for Swift 7
let _: ((a: Int, b: Int)) -> Void = fn1
// expected-swift6-warning@-1 {{tuple conversion from '(a: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
// expected-swift7-error@-2 {{tuple conversion from '(a: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
let _: ((x: Int, b: Int)) -> Void = fn1
// expected-swift6-warning@-1 {{tuple conversion from '(x: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
// expected-swift7-error@-2 {{tuple conversion from '(x: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}}
let _: () -> (y: Int, Int) = fn2
// expected-swift6-warning@-1 {{tuple conversion from '(x: Int, Int)' to '(y: Int, Int)' mismatches labels}}
// expected-swift7-error@-2 {{tuple conversion from '(x: Int, Int)' to '(y: Int, Int)' mismatches labels}}
let _: () -> (y: Int, k: Int) = fn2
// expected-swift6-warning@-1 {{tuple conversion from '(x: Int, Int)' to '(y: Int, k: Int)' mismatches labels}}
// expected-swift7-error@-2 {{tuple conversion from '(x: Int, Int)' to '(y: Int, k: Int)' mismatches labels}}
// Attempting to shuffle has always been illegal here
let _: () -> (y: Int, x: Int) = fn2
// expected-error@-1 {{cannot convert value of type '() -> (x: Int, Int)' to specified type '() -> (y: Int, x: Int)'}}
// Losing labels is okay though.
let _: () -> (Int, Int) = fn2
// Gaining labels also okay.
let _: ((x: Int, Int)) -> Void = fn1
let _: () -> (x: Int, y: Int) = fn2
let _: () -> (Int, y: Int) = fn2
}