mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
zig fmt: recovery: missing while rbrace
Previously, this test case resulted in zig fmt entering an endless loop.
This commit is contained in:
parent
041212a41c
commit
434fce2146
@ -937,14 +937,17 @@ const Parser = struct {
|
||||
/// If a parse error occurs, reports an error, but then finds the next statement
|
||||
/// and returns that one instead. If a parse error occurs but there is no following
|
||||
/// statement, returns 0.
|
||||
fn expectStatementRecoverable(p: *Parser) error{OutOfMemory}!Node.Index {
|
||||
fn expectStatementRecoverable(p: *Parser) Error!Node.Index {
|
||||
while (true) {
|
||||
return p.expectStatement() catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
error.ParseError => {
|
||||
p.findNextStmt(); // Try to skip to the next statement.
|
||||
if (p.token_tags[p.tok_i] == .r_brace) return null_node;
|
||||
continue;
|
||||
switch (p.token_tags[p.tok_i]) {
|
||||
.r_brace => return null_node,
|
||||
.eof => return error.ParseError,
|
||||
else => continue,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -4580,6 +4580,16 @@ test "recovery: missing comma in params" {
|
||||
});
|
||||
}
|
||||
|
||||
test "recovery: missing while rbrace" {
|
||||
try testError(
|
||||
\\fn a() b {
|
||||
\\ while (d) {
|
||||
\\}
|
||||
, &[_]Error{
|
||||
.expected_statement,
|
||||
});
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const warn = std.debug.warn;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user