properly parse anon literal in array

This commit is contained in:
Vexu
2019-11-17 17:07:48 +02:00
committed by Andrew Kelley
parent 8c4784f9c1
commit 6cddf9d723
4 changed files with 42 additions and 2 deletions

View File

@@ -2025,7 +2025,12 @@ static AstNode *ast_parse_field_init(ParseContext *pc) {
if (first == nullptr)
return nullptr;
Token *name = expect_token(pc, TokenIdSymbol);
Token *name = eat_token_if(pc, TokenIdSymbol);
if (name == nullptr) {
// Because of anon literals ".{" is also valid.
put_back_token(pc);
return nullptr;
}
if (eat_token_if(pc, TokenIdEq) == nullptr) {
// Because ".Name" can also be intepreted as an enum literal, we should put back
// those two tokens again so that the parser can try to parse them as the enum