fix(parser): improve parserParseBlock infinite-loop safeguard for stuck at }

This commit is contained in:
2026-06-07 17:01:15 +03:00
parent e41a8d31df
commit 88af8b09d4
+8 -2
View File
@@ -869,8 +869,13 @@ func parserParseBlock(p: *Parser) -> *Block {
}
let beforePos: int = p.pos;
let s: *Stmt = parserParseStmt(p);
// Infinite-loop safeguard: if no progress, advance past current token
// Infinite-loop safeguard
if p.pos == beforePos {
// If stuck and current token is }, consume it and exit
if parserCheck(p, tkRBrace) {
discard parserAdvance(p);
break;
}
discard parserAdvance(p);
continue;
}
@@ -886,7 +891,8 @@ func parserParseBlock(p: *Parser) -> *Block {
b.stmtCount = b.stmtCount + 1;
}
}
discard parserExpect(p, tkRBrace, "expected '}'");
// Consume } if present (may already be consumed by safeguard)
parserMatch(p, tkRBrace);
return b;
}