Skip to content

Commit 8265789

Browse files
committed
Drop the Identifier List from Designated Type Parsing
This was never the correct way to model this because it drops the commas in the list. Instead just take the optional trailing identifier element if we have one.
1 parent 5e8dc12 commit 8265789

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8863,12 +8863,13 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
88638863
return makeParserCodeCompletionResult<OperatorDecl>();
88648864
}
88658865

8866-
SyntaxParsingContext ListCtxt(SyntaxContext, SyntaxKind::IdentifierList);
8867-
88688866
(void)parseIdentifier(groupName, groupLoc,
88698867
diag::operator_decl_expected_precedencegroup,
88708868
/*diagnoseDollarPrefix=*/false);
88718869

8870+
SyntaxParsingContext ListCtxt(SyntaxContext,
8871+
SyntaxKind::DesignatedTypeList);
8872+
88728873
if (Context.TypeCheckerOpts.EnableOperatorDesignatedTypes) {
88738874
// Designated types have been removed; consume the list (mainly for source
88748875
// compatibility with old swiftinterfaces) and emit a warning.
@@ -8885,9 +8886,17 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
88858886
typesEndLoc = groupLoc;
88868887
}
88878888

8888-
while (consumeIf(tok::comma, typesEndLoc)) {
8889-
if (Tok.isNot(tok::eof))
8889+
while (Tok.isNot(tok::eof)) {
8890+
SyntaxParsingContext ElementCtxt(SyntaxContext,
8891+
SyntaxKind::DesignatedTypeElement);
8892+
if (!consumeIf(tok::comma, typesEndLoc)) {
8893+
ElementCtxt.setTransparent();
8894+
break;
8895+
}
8896+
8897+
if (Tok.isNot(tok::eof)) {
88908898
typesEndLoc = consumeToken();
8899+
}
88918900
}
88928901

88938902
if (typesEndLoc.isValid())

test/Parse/operator_decl_designated_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types -verify-syntax-tree
1+
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types
22

33
precedencegroup LowPrecedence {
44
associativity: right

0 commit comments

Comments
 (0)