diff --git a/internal/wwfixture/types.ww b/internal/wwfixture/types.ww index e80011e5..75cd07f2 100644 --- a/internal/wwfixture/types.ww +++ b/internal/wwfixture/types.ww @@ -1,13 +1,13 @@ package wwfixture; def protocolversion: i32 = 1; -def corpuscount: i32 = 1730; +def corpuscount: i32 = 1731; def errorcount: i32 = 343; def compilecount: i32 = 22; def runcount: i32 = 209; -def runexitcount: i32 = 1156; -def nativecount: i32 = 3460; -def corpushash: str = "5c20c19b826359fcceb45c8db5cf405f39183a68783582eaaf5f38f0e88f3771"; +def runexitcount: i32 = 1157; +def nativecount: i32 = 3462; +def corpushash: str = "6786916caba20c07c47eaaa0507dd2707fd162b708904b6e72187afb02233bf9"; type directive = enum i32 { ERROR = 0, diff --git a/lib/ww/syntax/stmt.ww b/lib/ww/syntax/stmt.ww index 2f118e15..c226c5f3 100644 --- a/lib/ww/syntax/stmt.ww +++ b/lib/ww/syntax/stmt.ww @@ -141,11 +141,22 @@ fn parsefor(p: *parser) *node = { advance(p); // past `for` expecttok(p, tkind.TK_LPAREN, "expected '(' after for"); - // Four forms (matching C parser): + // Five forms (matching C parser): + // for () — empty cond, unconditional loop // for (cond) — only cond // for (init; cond; post) — C-style 3-clause // for (let x .. expr) — Hare-style range, single binding // for (let (a, b) .. expr) — range with tuple destructure + + // Empty condition: cond stays nil (no test emitted downstream). + // Mirrors cmd/wcc/parse.c:1027 — returns WITHOUT the for-else arm, + // exactly as the cstage empty form does. + if (p.curkind == tkind.TK_RPAREN) { + advance(p); + let n = newnode(nkind.N_FOR, pf, pl, pc); + n.body = parseblock(p); + return n; + }; // Range and 3-clause both lead with `let`, so we commit to consuming // `let` then disambiguate by looking at what follows. if (p.curkind == tkind.TK_LET) { diff --git a/test/wcc/data/r700_break_loop/case.ww b/test/wcc/data/r700_break_loop/case.ww new file mode 100644 index 00000000..d4e7627f --- /dev/null +++ b/test/wcc/data/r700_break_loop/case.ww @@ -0,0 +1,11 @@ +//ww:run-exit 7 +// Migrated from 700_e2e row 23. +package main; +fn main() i32 = { + let i: i32 = 0; + for () { + i += 1; + if (i == 7) { break; }; + }; + return i; +};