[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:
Hamish Knight
2022-08-02 13:56:30 +01:00
parent 227f0deb5b
commit 1bf954c61f
3 changed files with 42 additions and 3 deletions

View File

@@ -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.