Skip to content

Commit 8e81a80

Browse files
authored
[Parse] Fix a crash when there is nothing after the prefix/postfix operator colon (#60939)
1 parent 29c54c5 commit 8e81a80

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
@@ -8780,8 +8780,10 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
87808780
.fixItRemove({typesStartLoc, typesEndLoc});
87818781
} else {
87828782
if (isPrefix || isPostfix) {
8783+
// If we have nothing after the colon, then just remove the colon.
8784+
auto endLoc = groupLoc.isValid() ? groupLoc : colonLoc;
87838785
diagnose(colonLoc, diag::precedencegroup_not_infix)
8784-
.fixItRemove({colonLoc, groupLoc});
8786+
.fixItRemove({colonLoc, endLoc});
87858787
}
87868788
// Nothing to complete here, simply consume the token.
87878789
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)