Skip to content

Commit c70d281

Browse files
hyperpolymathclaude
andcommitted
fix(parser): enforce trailing semicolon on field_decl
Previously parseFieldDecl discarded the result of `expect(p, Semicolon)` via `let _ = ...`, silently accepting a missing trailing `;` on a region field. That contradicted EBNF grammar.ebnf §field_decl which requires the semicolon. Fix: propagate the Semicolon error. L1 test suite gains a case locking in the stricter behaviour. All other suites still pass: - ParserTests: 88/88 (unchanged) - E2E driver: 4/4 clean, 2 honest-skip for L11/L12 - L1-L3: 17/17 (was 16; L1 grew from 7 to 8) Scope sweep confirmed no regression risk: grep for field-like lines without `;` surfaced 12 hits, all function parameters (comma-separated, not field_decls). No example / test fixture relied on the old looseness. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e8b3f6a commit c70d281

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/parser/Parser.res

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,8 +1331,14 @@ let parseFieldDecl = (p: parserState): result<Ast.located<Ast.fieldDecl>> => {
13311331
| Error(_) => ()
13321332
}
13331333
}
1334-
let _ = expect(p, Semicolon)
1335-
Ok({node: {name, fieldType: ty, constraints}, loc: startLoc})
1334+
// EBNF grammar.ebnf §field_decl requires the trailing semicolon.
1335+
// Older fixtures relied on a silent `let _ = expect(...)` that
1336+
// discarded the error; enforce it now so parse-time L1 coverage
1337+
// matches the spec.
1338+
switch expect(p, Semicolon) {
1339+
| Ok() => Ok({node: {name, fieldType: ty, constraints}, loc: startLoc})
1340+
| Error(e) => Error(e)
1341+
}
13361342
| Error(e) => Error(e)
13371343
}
13381344
| Error(e) => Error(e)

tests/levels/L1.mjs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ expectOk(
6666

6767
// ── Negative: canonical syntax errors ────────────────────────────────
6868

69-
// Finding 2026-04-18: parser is lenient about the semicolon between
70-
// the last field and `align`. Grammar EBNF requires `;` after every
71-
// field_decl, so this is a parser looseness worth flagging in a
72-
// future parser-tightness pass. Not exercised here to keep L1 tests
73-
// aligned with current parser behaviour rather than the EBNF spec.
69+
// Parser now enforces the trailing `;` on every field_decl per
70+
// grammar.ebnf §field_decl. A missing `;` between the last field and
71+
// the region's `align` line is rejected rather than silently accepted.
7472

7573
expectErr(
7674
`region Bad { n: u32;
@@ -79,6 +77,14 @@ expectErr(
7977
"align with missing integer literal",
8078
);
8179

80+
expectErr(
81+
`region Bad {
82+
n: u32
83+
align 4;
84+
}`,
85+
"field decl missing trailing semicolon",
86+
);
87+
8288
expectErr(
8389
`region Bad {
8490
n: u32;

0 commit comments

Comments
 (0)