diff options
| author | gingerBill <bill@gingerbill.org> | 2025-05-29 16:29:52 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2025-05-29 16:29:52 +0100 |
| commit | 74bab6d42faf02b26fc6690957277842a9462694 (patch) | |
| tree | db39bdcbe59adc90480f318d6ba2258c932a4bd2 /src/parser.cpp | |
| parent | 1627a4015f5a0b66541d7469211e14736360c3da (diff) | |
Fix #5232 by adding an edge case
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index a397585e8..0057ab611 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3274,6 +3274,8 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { case Token_OpenBracket: { bool prev_allow_range = f->allow_range; f->allow_range = false; + defer (f->allow_range = prev_allow_range); + Token open = {}, close = {}, interval = {}; Ast *indices[2] = {}; @@ -3282,6 +3284,13 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { f->expr_level++; open = expect_token(f, Token_OpenBracket); + if (f->curr_token.kind == Token_CloseBracket) { + error(f->curr_token, "Expected an operand, got ]"); + close = expect_token(f, Token_CloseBracket); + operand = ast_index_expr(f, operand, nullptr, open, close); + break; + } + switch (f->curr_token.kind) { case Token_Ellipsis: case Token_RangeFull: @@ -3331,7 +3340,6 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { operand = ast_index_expr(f, operand, indices[0], open, close); } - f->allow_range = prev_allow_range; } break; case Token_Pointer: // Deference |