Skip to content
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
12 changes: 8 additions & 4 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5863,12 +5863,16 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {

// Move requires postfix comma only if argument is moved in-between
// other arguments.
bool requiresComma =
!isExpr<BinaryExpr>(anchor) && PrevArgIdx != args->size() - 1;
std::string argumentSeparator;
if (auto *BE = getAsExpr<BinaryExpr>(anchor)) {
auto operatorName = std::string(*getOperatorName(BE->getFn()));
argumentSeparator = " " + operatorName + " ";
} else if (PrevArgIdx != args->size() - 1) {
argumentSeparator = ", ";
}

diag.fixItRemove(removalRange);
diag.fixItInsert(secondRange.Start,
text.str() + (requiresComma ? ", " : ""));
diag.fixItInsert(secondRange.Start, text.str() + argumentSeparator);
};

// There are 4 diagnostic messages variations depending on
Expand Down
3 changes: 2 additions & 1 deletion test/Parse/operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ var _ : TheDevil = God()^
var _ : God = ^TheDevil()
var _ : Man = TheDevil() ^ God()
var _ : Man = God()^ ^ ^TheDevil()
let _ = God()^TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil()}} {{14-25=}}
let _ = God()^TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil() ^ }} {{14-25=}}
let _ = God() ^ TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil() ^ }} {{14-27=}}

postfix func ^ (x: Man) -> () -> God {
return { return God() }
Expand Down