Skip to content

Syntax: synthesize right brace tokens if they are missing from nominal type decls. #24050

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 1 commit into from
Apr 16, 2019
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
5 changes: 4 additions & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3507,7 +3507,10 @@ bool Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
}
}
}
parseMatchingToken(tok::r_brace, RBLoc, ErrorDiag, LBLoc);
if (parseMatchingToken(tok::r_brace, RBLoc, ErrorDiag, LBLoc)) {
// Synthesize an r_brace syntax node if the token is absent
SyntaxContext->synthesize(tok::r_brace, RBLoc);
}

// Increase counter.
if (auto *stat = Context.Stats) {
Expand Down
8 changes: 7 additions & 1 deletion test/Syntax/Outputs/round_trip_invalid.swift.withkinds
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ let <PatternBinding><IdentifierPattern>strings</IdentifierPattern><TypeAnnotatio

// Function body without closing brace token.
func foo<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<VariableDecl>
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <IntegerLiteralExpr>2</IntegerLiteralExpr></InitializerClause></PatternBinding></VariableDecl></CodeBlock></FunctionDecl>
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <IntegerLiteralExpr>2</IntegerLiteralExpr></InitializerClause></PatternBinding></VariableDecl><ClassDecl>

class C <MemberDeclBlock>{<MemberDeclListItem><StructDecl>
struct S <MemberDeclBlock>{<MemberDeclListItem><EnumDecl>
enum E <MemberDeclBlock>{<MemberDeclListItem><ProtocolDecl>
protocol P <MemberDeclBlock>{<MemberDeclListItem><ExtensionDecl>
extension <SimpleTypeIdentifier>P </SimpleTypeIdentifier><MemberDeclBlock>{</MemberDeclBlock></ExtensionDecl></MemberDeclListItem></MemberDeclBlock></ProtocolDecl></MemberDeclListItem></MemberDeclBlock></EnumDecl></MemberDeclListItem></MemberDeclBlock></StructDecl></MemberDeclListItem></MemberDeclBlock></ClassDecl></CodeBlock></FunctionDecl>
6 changes: 6 additions & 0 deletions test/Syntax/round_trip_invalid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ let strings: [Strin[g]?
// Function body without closing brace token.
func foo() {
var a = 2

class C {
struct S {
enum E {
protocol P {
extension P {
2 changes: 1 addition & 1 deletion utils/gyb_syntax_support/DeclNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
element='MemberDeclListItem'),

# member-decl = decl ';'?
Node('MemberDeclListItem', kind='Syntax',
Node('MemberDeclListItem', kind='Syntax', omit_when_empty=True,
description='''
A member declaration of a type consisting of a declaration and an \
optional semicolon;
Expand Down