[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

@@ -1586,9 +1586,9 @@ WARNING(coercion_may_fail_warning,none,
"coercion from %0 to %1 may fail; use 'as?' or 'as!' instead",
(Type, Type))
WARNING(tuple_label_mismatch_warning,none,
"tuple conversion from %0 to %1 mismatches labels",
(Type, Type))
ERROR(tuple_label_mismatch,none,
"tuple conversion from %0 to %1 mismatches labels",
(Type, Type))
ERROR(missing_explicit_conversion,none,
"%0 is not implicitly convertible to %1; "

View File

@@ -3458,7 +3458,8 @@ public:
}
};
/// Emit a warning for mismatched tuple labels.
/// Emit a warning for mismatched tuple labels, which is upgraded to an error
/// for a future language mode.
class AllowTupleLabelMismatch final : public ContextualMismatch {
AllowTupleLabelMismatch(ConstraintSystem &cs, Type fromType, Type toType,
ConstraintLocator *locator)

View File

@@ -9419,8 +9419,9 @@ bool InvalidWeakAttributeUse::diagnoseAsError() {
}
bool TupleLabelMismatchWarning::diagnoseAsError() {
emitDiagnostic(diag::tuple_label_mismatch_warning, getFromType(), getToType())
.highlight(getSourceRange());
emitDiagnostic(diag::tuple_label_mismatch, getFromType(), getToType())
.highlight(getSourceRange())
.warnUntilFutureSwiftVersion();
return true;
}

View File

@@ -3009,7 +3009,8 @@ public:
bool diagnoseAsError() override;
};
/// Emit a warning for mismatched tuple labels.
/// Emit a warning for mismatched tuple labels, which is upgraded to an error
/// for a future language mode.
class TupleLabelMismatchWarning final : public ContextualFailure {
public:
TupleLabelMismatchWarning(const Solution &solution, Type fromType,

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
}