Skip to content

[Parse] Fix a crash when there is nothing after the prefix/postfix operator colon #60939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 3 additions & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8745,8 +8745,10 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
.fixItRemove({typesStartLoc, typesEndLoc});
} else {
if (isPrefix || isPostfix) {
// If we have nothing after the colon, then just remove the colon.
auto endLoc = groupLoc.isValid() ? groupLoc : colonLoc;
diagnose(colonLoc, diag::precedencegroup_not_infix)
.fixItRemove({colonLoc, groupLoc});
.fixItRemove({colonLoc, endLoc});
}
// Nothing to complete here, simply consume the token.
if (Tok.is(tok::code_complete))
Expand Down
5 changes: 5 additions & 0 deletions test/Parse/operator_decl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ protocol Proto {}
infix operator *<*< : F, Proto
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{expected expression}}

// https://github.com/apple/swift/issues/60932

// expected-error@+2 {{expected precedence group name after ':' in operator declaration}}
postfix operator ++: // expected-error {{only infix operators may declare a precedence}} {{20-21=}}