Skip to content

Commit 05350cd

Browse files
committed
[libSyntax] Fix parsing of delayed function bodies
1 parent 00604fb commit 05350cd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,7 +3870,11 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
38703870
return ParameterList::create(P.Context, StartLoc, param, EndLoc);
38713871
}
38723872

3873-
static unsigned skipUntilMatchingRBrace(Parser &P) {
3873+
static unsigned skipUntilMatchingRBrace(Parser &P,
3874+
SyntaxParsingContext *&SyntaxContext) {
3875+
SyntaxParsingContext BlockItemListContext(SyntaxContext,
3876+
SyntaxKind::CodeBlockItemList);
3877+
SyntaxParsingContext BodyContext(SyntaxContext, SyntaxKind::TokenList);
38743878
unsigned OpenBraces = 1;
38753879
while (OpenBraces != 0 && P.Tok.isNot(tok::eof)) {
38763880
if (P.consumeIf(tok::l_brace)) {
@@ -3888,9 +3892,11 @@ static unsigned skipUntilMatchingRBrace(Parser &P) {
38883892
return OpenBraces;
38893893
}
38903894

3891-
static unsigned skipBracedBlock(Parser &P) {
3895+
static unsigned skipBracedBlock(Parser &P,
3896+
SyntaxParsingContext *&SyntaxContext) {
3897+
SyntaxParsingContext CodeBlockContext(SyntaxContext, SyntaxKind::CodeBlock);
38923898
P.consumeToken(tok::l_brace);
3893-
unsigned OpenBraces = skipUntilMatchingRBrace(P);
3899+
unsigned OpenBraces = skipUntilMatchingRBrace(P, SyntaxContext);
38943900
if (P.consumeIf(tok::r_brace))
38953901
OpenBraces--;
38963902
return OpenBraces;
@@ -3904,7 +3910,7 @@ void Parser::consumeGetSetBody(AbstractFunctionDecl *AFD,
39043910
BodyRange.Start = Tok.getLoc();
39053911

39063912
// Skip until the next '}' at the correct nesting level.
3907-
unsigned OpenBraces = skipUntilMatchingRBrace(*this);
3913+
unsigned OpenBraces = skipUntilMatchingRBrace(*this, SyntaxContext);
39083914

39093915
if (OpenBraces != 1) {
39103916
// FIXME: implement some error recovery?
@@ -5102,7 +5108,7 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
51025108
BodyRange.Start = Tok.getLoc();
51035109

51045110
// Consume the '{', and find the matching '}'.
5105-
unsigned OpenBraces = skipBracedBlock(*this);
5111+
unsigned OpenBraces = skipBracedBlock(*this, SyntaxContext);
51065112
if (OpenBraces != 0 && Tok.isNot(tok::code_complete)) {
51075113
assert(Tok.is(tok::eof));
51085114
// We hit EOF, and not every brace has a pair. Recover by searching
@@ -6458,7 +6464,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
64586464
(void) consumeIf(tok::r_brace);
64596465
} else if (Tok.isNot(tok::eof) && peekToken().is(tok::l_brace)) {
64606466
consumeToken();
6461-
skipBracedBlock(*this);
6467+
skipBracedBlock(*this, SyntaxContext);
64626468
}
64636469
return nullptr;
64646470
}

lib/Parse/ParseExpr.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,8 +3563,13 @@ ParserResult<Expr> Parser::parseExprTypeOf() {
35633563
// DynamicTypeExpr.
35643564
SyntaxParsingContext CallCtxt(SyntaxContext, SyntaxKind::FunctionCallExpr);
35653565

3566-
// Consume 'type'
3567-
SourceLoc keywordLoc = consumeToken();
3566+
SourceLoc keywordLoc;
3567+
{
3568+
SyntaxParsingContext IdentifierExprContext(SyntaxContext,
3569+
SyntaxKind::IdentifierExpr);
3570+
// Consume 'type'
3571+
keywordLoc = consumeToken();
3572+
}
35683573

35693574
// Parse the leading '('.
35703575
SourceLoc lParenLoc = consumeToken(tok::l_paren);

0 commit comments

Comments
 (0)