Skip to content

Commit 8c7c19d

Browse files
committed
[Diagnostics] Avoid adding comma when reordering with last argument
(cherry picked from commit e086896)
1 parent 250bc5f commit 8c7c19d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4825,9 +4825,14 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {
48254825
SourceRange removalRange{Lexer::getLocForEndOfToken(SM, removalStartLoc),
48264826
firstRange.End};
48274827

4828+
// Move requires postfix comma only if argument is moved in-between
4829+
// other arguments.
4830+
bool requiresComma = !isExpr<BinaryExpr>(anchor) &&
4831+
PrevArgIdx != tuple->getNumElements() - 1;
4832+
48284833
diag.fixItRemove(removalRange);
48294834
diag.fixItInsert(secondRange.Start,
4830-
text.str() + (isExpr<BinaryExpr>(anchor) ? "" : ", "));
4835+
text.str() + (requiresComma ? ", " : ""));
48314836
};
48324837

48334838
// There are 4 diagnostic messages variations depending on

test/Constraints/argument_matching.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,10 +1752,10 @@ func rdar70764991() {
17521752
static var foo: S { get { S() } }
17531753
}
17541754

1755-
func bar(_: Any, foo: String) {
1755+
func bar(_: Any, _: String) {
17561756
}
17571757

17581758
func test(_ str: String) {
1759-
bar(str, foo: S.foo) // expected-error {{unnamed argument #1 must precede argument 'foo'}} {{9-12=}} {{14-14=str, }}
1759+
bar(str, S.foo) // expected-error {{unnamed argument #1 must precede unnamed argument #2}} {{9-12=}} {{14-14=str}}
17601760
}
17611761
}

0 commit comments

Comments
 (0)