Skip to content

Commit e086896

Browse files
committed
[Diagnostics] Avoid adding comma when reordering with last argument
1 parent 09f3461 commit e086896

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
@@ -4836,9 +4836,14 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {
48364836
SourceRange removalRange{Lexer::getLocForEndOfToken(SM, removalStartLoc),
48374837
firstRange.End};
48384838

4839+
// Move requires postfix comma only if argument is moved in-between
4840+
// other arguments.
4841+
bool requiresComma = !isExpr<BinaryExpr>(anchor) &&
4842+
PrevArgIdx != tuple->getNumElements() - 1;
4843+
48394844
diag.fixItRemove(removalRange);
48404845
diag.fixItInsert(secondRange.Start,
4841-
text.str() + (isExpr<BinaryExpr>(anchor) ? "" : ", "));
4846+
text.str() + (requiresComma ? ", " : ""));
48424847
};
48434848

48444849
// 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)