mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Downgrade multi-param default inference diag for methods
We recently started enforcing this rule for methods, downgrade to a warning until the next language mode to avoid source compatibility breakage.
This commit is contained in:
@@ -669,12 +669,19 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
|
||||
affectedParams, [&](const unsigned index) { params << "#" << index; },
|
||||
[&] { params << ", "; });
|
||||
|
||||
ctx.Diags.diagnose(
|
||||
auto diag = ctx.Diags.diagnose(
|
||||
defaultValue->getLoc(),
|
||||
diag::
|
||||
cannot_default_generic_parameter_inferrable_from_another_parameter,
|
||||
paramInterfaceTy, params.str());
|
||||
return Type();
|
||||
|
||||
// In Swift 6.2 and below we incorrectly missed checking this rule for
|
||||
// methods, downgrade to a warning until the next language mode.
|
||||
auto futureVersion = version::Version::getFutureMajorLanguageVersion();
|
||||
if (!anchor->hasCurriedSelf() || ctx.isSwiftVersionAtLeast(futureVersion))
|
||||
return Type();
|
||||
|
||||
diag.warnUntilFutureSwiftVersion();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ func testInferenceFromClosureVarInvalid<T>(x: T = { let x = "" as Int; return x
|
||||
// https://github.com/swiftlang/swift/issues/72199
|
||||
enum S72199_1 {
|
||||
func testS72199_1<T>(_: T = 42, _: [T]) {}
|
||||
// expected-error@-1 {{cannot use default expression for inference of 'T' because it is inferrable from parameters #0, #1}}
|
||||
// expected-warning@-1 {{cannot use default expression for inference of 'T' because it is inferrable from parameters #0, #1; this will be an error in a future Swift language mode}}
|
||||
}
|
||||
|
||||
func testS72199_2<T: P>(x: T.X, y: T = S()) { } // Ok
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// RUN: %target-typecheck-verify-swift -swift-version 7
|
||||
// REQUIRES: swift7
|
||||
|
||||
// https://github.com/swiftlang/swift/issues/72199
|
||||
enum S72199_1 {
|
||||
func testS72199_1<T>(_: T = 42, _: [T]) {}
|
||||
// expected-error@-1 {{cannot use default expression for inference of 'T' because it is inferrable from parameters #0, #1}}
|
||||
}
|
||||
|
||||
func testS72199<T>(_: T = 42, _: [T]) {}
|
||||
// expected-error@-1 {{cannot use default expression for inference of 'T' because it is inferrable from parameters #0, #1}}
|
||||
Reference in New Issue
Block a user