Skip to content

Commit 7c653e4

Browse files
authored
Merge pull request #39257 from LucianoPAlmeida/SR-15179-dupe-arg-fix
[Sema][SR-15179] Ignore FunctionArgument inout mismatch if there is already a fix for locator
2 parents a2860ec + d53a862 commit 7c653e4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,6 +4410,11 @@ bool ConstraintSystem::repairFailures(
44104410
loc))
44114411
return true;
44124412

4413+
// There is already a remove extraneous arguments fix recorded for this
4414+
// apply arg to param locator, so let's skip the default argument mismatch.
4415+
if (hasFixFor(loc, FixKind::RemoveExtraneousArguments))
4416+
return true;
4417+
44134418
conversionsOrFixes.push_back(
44144419
AllowArgumentMismatch::create(*this, lhs, rhs, loc));
44154420
break;
@@ -4497,8 +4502,18 @@ bool ConstraintSystem::repairFailures(
44974502
break;
44984503
}
44994504

4505+
auto *parentLoc = getConstraintLocator(anchor, path);
4506+
45004507
if ((lhs->is<InOutType>() && !rhs->is<InOutType>()) ||
45014508
(!lhs->is<InOutType>() && rhs->is<InOutType>())) {
4509+
// Since `FunctionArgument` as a last locator element represents
4510+
// a single parameter of the function type involved in a conversion
4511+
// to another function type, see `matchFunctionTypes`. If there is already
4512+
// a fix for the this convertion, we can just ignore individual function
4513+
// argument in-out mismatch failure by considered this fixed.
4514+
if (hasFixFor(parentLoc))
4515+
return true;
4516+
45024517
// We want to call matchTypes with the default decomposition options
45034518
// in case there are type variables that we couldn't bind due to the
45044519
// inout attribute mismatch.
@@ -4514,7 +4529,6 @@ bool ConstraintSystem::repairFailures(
45144529
}
45154530
}
45164531

4517-
auto *parentLoc = getConstraintLocator(anchor, path);
45184532
// In cases like this `FunctionArgument` as a last locator element
45194533
// represents a single parameter of the function type involved in
45204534
// a conversion to another function type, see `matchFunctionTypes`.

test/Concurrency/isolated_parameters.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ func tuplify<Ts>(_ fn: (Ts) -> Void) {} // expected-note {{in call to function '
107107

108108
@available(SwiftStdlib 5.5, *)
109109
func testTuplingIsolated(_ a: isolated A, _ b: isolated A) {
110-
// FIXME: We shouldn't duplicate the "cannot convert value of type" diagnostic (SR-15179)
111110
tuplify(testTuplingIsolated)
112111
// expected-error@-1 {{generic parameter 'Ts' could not be inferred}}
113-
// expected-error@-2 2{{cannot convert value of type '(isolated A, isolated A) -> ()' to expected argument type '(Ts) -> Void'}}
112+
// expected-error@-2 {{cannot convert value of type '(isolated A, isolated A) -> ()' to expected argument type '(Ts) -> Void'}}
114113
}

test/Constraints/function.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,12 @@ func testInvalidTupleImplosions() {
263263
func takesInout(_ x: Int, _ y: inout String) {}
264264
tuplify(takesInout) // expected-error {{cannot convert value of type '(Int, inout String) -> ()' to expected argument type '(Int) -> Void'}}
265265
}
266+
267+
// SR-15179
268+
func SR15179<Ts>(_ fn: @escaping (Ts) -> Void) {} // expected-note {{in call to function 'SR15179'}}
269+
func fn1(x: Int..., y: Int...) {}
270+
SR15179(fn1) // expected-error {{cannot convert value of type '(Int..., Int...) -> ()' to expected argument type '(Ts) -> Void'}}
271+
// expected-error@-1{{generic parameter 'Ts' could not be inferred}}
272+
273+
func fn(_ x: inout Int, _ y: inout Int) {}
274+
SR15179(fn) // expected-error {{cannot convert value of type '(inout Int, inout Int) -> ()' to expected argument type '(Int) -> Void'}}

0 commit comments

Comments
 (0)