Skip to content

Commit 6113266

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

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not %target-typecheck-verify-swift
2+
3+
// https://github.com/apple/swift/issues/60932
4+
5+
// expected-error@+1 {{expected precedence group name after ':' in operator declaration}}
6+
prefix operator ++: // expected-error {{only infix operators may declare a precedence}} {{19-20=}}

0 commit comments

Comments
 (0)