Skip to content

Commit 0485065

Browse files
committed
[CSFix] Make sure single parameter tuple splat is detected correctly
In situations like: ```swift func foo<T>(x: T) {} foo(a; 0, x: 42) ``` Let's not try to fix call to `foo` as a tuple splat because match is in a middle of the argument list, it should be considered a regular extraneous argument instead.
1 parent 8d3409b commit 0485065

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/Sema/CSFix.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,15 @@ bool AllowTupleSplatForSingleParameter::attempt(
751751
//
752752
// We'd want to suggest argument list to be `x: (0, 1)` instead
753753
// of `(x: 0, 1)` which would be incorrect.
754-
if (index == 0 && param.getLabel() == label)
755-
label = Identifier();
754+
if (param.hasLabel() && label == param.getLabel()) {
755+
if (index == 0) {
756+
label = Identifier();
757+
} else {
758+
// If label match anything other than first argument,
759+
// this can't be a tuple splat.
760+
return true;
761+
}
762+
}
756763

757764
// Tuple can't have `inout` elements.
758765
if (flags.isInOut())

0 commit comments

Comments
 (0)