wcc/ww: reject (a,) single-element trailing-comma tuple (catB-92)
wwstage's tuple-parse loop checked the RPAREN-break at the top, so `(a,)` parsed as a 1-element N_TUPLE and reached cgen — a silent wrong-accept. A trailing comma is legal only after >=2 elements. Align the loop order to cstage cmd/wcc/parse.c:552-558 (parse each element before the RPAREN-break); `(a,)` now errors at the next parseexpr, `(a, b)` / `(a, b,)` are unchanged. cstage already rejected; this brings wwstage's w6c_ww parser into agreement. Regen w6c/wwdump combined.ww (parser embeds in both). Valid-program codegen unchanged → cs==ww byte-id gate stays green.
This commit is contained in:
@@ -8268,12 +8268,16 @@ fn parseprimary(p: *parser) *node = {
|
||||
let t: *node = newnode(nkind.N_TUPLE, pf, pl, pc);
|
||||
t.list = e;
|
||||
let tail: *node = e;
|
||||
// Parse each element BEFORE the RPAREN-break so `(a,)`
|
||||
// (a single elem + trailing comma) is a loud parse error;
|
||||
// a trailing comma is legal only after >=2 elems. Mirror
|
||||
// cstage cmd/wcc/parse.c:552-558 loop order.
|
||||
for (true) {
|
||||
if (p.curkind == tkind.TK_RPAREN) { break; };
|
||||
let en: *node = parseexpr(p);
|
||||
tail.next = en;
|
||||
tail = en;
|
||||
if (!accepttok(p, tkind.TK_COMMA)) { break; };
|
||||
if (p.curkind == tkind.TK_RPAREN) { break; };
|
||||
};
|
||||
expecttok(p, tkind.TK_RPAREN, "expected ')' in tuple");
|
||||
return t;
|
||||
|
||||
Reference in New Issue
Block a user