parser: fix while-type-expr continue parsing and comptime labeled blocks
Fix two parser bugs found by auditing against upstream Parse.zig:
1. In parseTypeExpr's while case, the continue expression was parsed
inline as `eatToken(COLON) ? expectExpr : 0` which missed the
required parentheses. Use parseWhileContinueExpr(p) instead,
matching what parseWhileExpr already does.
2. In expectStatement, comptime blocks used parseBlock() which only
matches `{ ... }`. Use parseBlockExpr() to also recognize labeled
blocks like `comptime label: { ... }`.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
5
parser.c
5
parser.c
@@ -711,7 +711,7 @@ static AstNodeIndex expectStatement(Parser* p, bool allow_defer_var) {
|
||||
const AstTokenIndex comptime_token = eatToken(p, TOKEN_KEYWORD_COMPTIME);
|
||||
if (comptime_token != null_token) {
|
||||
// comptime followed by block => comptime block statement
|
||||
const AstNodeIndex block = parseBlock(p);
|
||||
const AstNodeIndex block = parseBlockExpr(p);
|
||||
if (block != 0) {
|
||||
return addNode(&p->nodes,
|
||||
(AstNodeItem) {
|
||||
@@ -1728,8 +1728,7 @@ static AstNodeIndex parseTypeExpr(Parser* p) {
|
||||
const AstNodeIndex condition = expectExpr(p);
|
||||
expectToken(p, TOKEN_R_PAREN);
|
||||
parsePtrPayload(p);
|
||||
const AstNodeIndex cont_expr
|
||||
= eatToken(p, TOKEN_COLON) != null_token ? expectExpr(p) : 0;
|
||||
const AstNodeIndex cont_expr = parseWhileContinueExpr(p);
|
||||
const AstNodeIndex body = parseTypeExpr(p);
|
||||
if (eatToken(p, TOKEN_KEYWORD_ELSE) != null_token) {
|
||||
parsePayload(p);
|
||||
|
||||
Reference in New Issue
Block a user