Skip to content

[Sema][SR-15179] Ignore FunctionArgument inout mismatch if there is already a fix for locator #39257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4410,6 +4410,11 @@ bool ConstraintSystem::repairFailures(
loc))
return true;

// There is already a remove extraneous arguments fix recorded for this
// apply arg to param locator, so let's skip the default argument mismatch.
if (hasFixFor(loc, FixKind::RemoveExtraneousArguments))
return true;

conversionsOrFixes.push_back(
AllowArgumentMismatch::create(*this, lhs, rhs, loc));
break;
Expand Down Expand Up @@ -4497,8 +4502,18 @@ bool ConstraintSystem::repairFailures(
break;
}

auto *parentLoc = getConstraintLocator(anchor, path);

if ((lhs->is<InOutType>() && !rhs->is<InOutType>()) ||
(!lhs->is<InOutType>() && rhs->is<InOutType>())) {
// Since `FunctionArgument` as a last locator element represents
// a single parameter of the function type involved in a conversion
// to another function type, see `matchFunctionTypes`. If there is already
// a fix for the this convertion, we can just ignore individual function
// argument in-out mismatch failure by considered this fixed.
if (hasFixFor(parentLoc))
return true;

// We want to call matchTypes with the default decomposition options
// in case there are type variables that we couldn't bind due to the
// inout attribute mismatch.
Expand All @@ -4514,7 +4529,6 @@ bool ConstraintSystem::repairFailures(
}
}

auto *parentLoc = getConstraintLocator(anchor, path);
// In cases like this `FunctionArgument` as a last locator element
// represents a single parameter of the function type involved in
// a conversion to another function type, see `matchFunctionTypes`.
Expand Down
3 changes: 1 addition & 2 deletions test/Concurrency/isolated_parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ func tuplify<Ts>(_ fn: (Ts) -> Void) {} // expected-note {{in call to function '

@available(SwiftStdlib 5.5, *)
func testTuplingIsolated(_ a: isolated A, _ b: isolated A) {
// FIXME: We shouldn't duplicate the "cannot convert value of type" diagnostic (SR-15179)
tuplify(testTuplingIsolated)
// expected-error@-1 {{generic parameter 'Ts' could not be inferred}}
// expected-error@-2 2{{cannot convert value of type '(isolated A, isolated A) -> ()' to expected argument type '(Ts) -> Void'}}
// expected-error@-2 {{cannot convert value of type '(isolated A, isolated A) -> ()' to expected argument type '(Ts) -> Void'}}
}
9 changes: 9 additions & 0 deletions test/Constraints/function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,12 @@ func testInvalidTupleImplosions() {
func takesInout(_ x: Int, _ y: inout String) {}
tuplify(takesInout) // expected-error {{cannot convert value of type '(Int, inout String) -> ()' to expected argument type '(Int) -> Void'}}
}

// SR-15179
func SR15179<Ts>(_ fn: @escaping (Ts) -> Void) {} // expected-note {{in call to function 'SR15179'}}
func fn1(x: Int..., y: Int...) {}
SR15179(fn1) // expected-error {{cannot convert value of type '(Int..., Int...) -> ()' to expected argument type '(Ts) -> Void'}}
// expected-error@-1{{generic parameter 'Ts' could not be inferred}}

func fn(_ x: inout Int, _ y: inout Int) {}
SR15179(fn) // expected-error {{cannot convert value of type '(inout Int, inout Int) -> ()' to expected argument type '(Int) -> Void'}}