mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CS] Better diagnose inout argument in tuple construction
Previously we relied on `TupleTypeElt::getType` returning an `InOutType` to fail the tuple type matching logic. Instead, add logic to reject any inout arguments up-front with a more specific diagnostic. Also, while we're here, strip the `_const` parameter flag, as it's not something that needs to be considered for tuple construction.
This commit is contained in:
@@ -573,7 +573,16 @@ func r22263468(_ a : String?) {
|
||||
// TODO(diagnostics): This is a regression from diagnosing missing optional unwrap for `a`, we have to
|
||||
// re-think the way errors in tuple elements are detected because it's currently impossible to detect
|
||||
// exactly what went wrong here and aggregate fixes for different elements at the same time.
|
||||
_ = MyTuple(42, a) // expected-error {{tuple type '(_const Int, String?)' is not convertible to tuple type 'MyTuple' (aka '(Int, String)')}}
|
||||
_ = MyTuple(42, a) // expected-error {{tuple type '(Int, String?)' is not convertible to tuple type 'MyTuple' (aka '(Int, String)')}}
|
||||
}
|
||||
|
||||
func testTupleConstructionInOutArg() {
|
||||
typealias II = (Int, Int)
|
||||
|
||||
var i = 0
|
||||
_ = (Int, Int)(&i, 0) // expected-error {{'&' may only be used to pass an argument to inout parameter}}
|
||||
_ = II(&i, 0) // expected-error {{'&' may only be used to pass an argument to inout parameter}}
|
||||
_ = II(&i, &i) // expected-error 2{{'&' may only be used to pass an argument to inout parameter}}
|
||||
}
|
||||
|
||||
// rdar://71829040 - "ambiguous without more context" error for tuple type mismatch.
|
||||
|
||||
Reference in New Issue
Block a user