Skip to content

Commit 64f6afa

Browse files
committed
[Parse] Fix a crash when there is nothing after the prefix/postfix operator colon
1 parent dc8cdcb commit 64f6afa

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8745,8 +8745,10 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
87458745
.fixItRemove({typesStartLoc, typesEndLoc});
87468746
} else {
87478747
if (isPrefix || isPostfix) {
8748+
// If we have nothing after the colon, then just remove the colon.
8749+
auto endLoc = groupLoc.isValid() ? groupLoc : colonLoc;
87488750
diagnose(colonLoc, diag::precedencegroup_not_infix)
8749-
.fixItRemove({colonLoc, groupLoc});
8751+
.fixItRemove({colonLoc, endLoc});
87508752
}
87518753
// Nothing to complete here, simply consume the token.
87528754
if (Tok.is(tok::code_complete))

test/Parse/operator_decl.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ protocol Proto {}
110110
infix operator *<*< : F, Proto
111111
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
112112
// expected-error@-2 {{expected expression}}
113+
114+
// https://github.com/apple/swift/issues/60932
115+
116+
// expected-error@+2 {{expected precedence group name after ':' in operator declaration}}
117+
postfix operator ++: // expected-error {{only infix operators may declare a precedence}} {{20-21=}}

0 commit comments

Comments
 (0)