Skip to content

Commit b2c054a

Browse files
CrazyFanFankongkaikai
authored andcommitted
Fixed issue #72085 where BinaryExpr fix-it suggested missing operator.
1 parent 8854438 commit b2c054a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,12 +5863,16 @@ bool OutOfOrderArgumentFailure::diagnoseAsError() {
58635863

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

58695874
diag.fixItRemove(removalRange);
5870-
diag.fixItInsert(secondRange.Start,
5871-
text.str() + (requiresComma ? ", " : ""));
5875+
diag.fixItInsert(secondRange.Start, text.str() + argumentSeparator);
58725876
};
58735877

58745878
// There are 4 diagnostic messages variations depending on

test/Parse/operators.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ var _ : TheDevil = God()^
8282
var _ : God = ^TheDevil()
8383
var _ : Man = TheDevil() ^ God()
8484
var _ : Man = God()^ ^ ^TheDevil()
85-
let _ = God()^TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil()}} {{14-25=}}
85+
let _ = God()^TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil() ^ }} {{14-25=}}
86+
let _ = God() ^ TheDevil() // expected-error{{operator argument #2 must precede operator argument #1}} {{9-9=TheDevil() ^ }} {{14-27=}}
8687

8788
postfix func ^ (x: Man) -> () -> God {
8889
return { return God() }

0 commit comments

Comments
 (0)