Skip to content

Parser: trait/impl/extend bodies take exactly the three §29.13 body forms - #1357

Merged
ehartford merged 1 commit into
fix-1349-tuple-pattern-if-subjectfrom
fix-1346-trait-impl-body-forms
Sep 23, 2026
Merged

ehartford merged 1 commit into
fix-1349-tuple-pattern-if-subjectfrom
fix-1346-trait-impl-body-forms

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1346. Stacked on #1347 (which repairs the 45 files that a bad rewrite scrambled into the rejected shape).

What changed

src/Parser.w parse_trait_decl and parse_impl_block now pick the body form once, in parse_decl_body_introducer, and find member boundaries through decl_member_continues. Before, they skipped newlines after : and took members until one started at column 0. src/Lexer.w gains line_indent_of.

Form Rule Diagnostic when broken
1, : then content one member; newlines inside its parentheses stay part of it an inline trait body is a single member: it ended at the end of the header line, so this member is outside it (§29.13), with the help end the line after \trait Foo:` and indent the first member like the rest, one member per line`
2, : ends the line members indented deeper than the header line expected an indented trait body after ':', the same rule as fn f:
3, { } members separated by newlines or semicolons (semicolons were rejected before this change)
bodyless impl Foo for X (§2.3) ends at its newline \`impl Foo for X\` has no ':' or '{', so it is a bodyless impl that ends at its newline; the indented lines below it are not its members (§29.13), with the help add ':' to the end of the header to make them its body: `impl Foo for X:`
anything else after an impl header expected ':' or '{' after the impl header (before, this fell through with no error)

Tests

  • compile_errors: err_trait_inline_body_then_indented_members, err_impl_inline_body_then_indented_members, err_impl_bodyless_then_indented_members, err_trait_colon_without_indented_body, err_impl_header_trailing_tokens
  • behavior: behav_1346_trait_impl_body_forms. It covers inline single-member traits and impls, including a parameter list split across lines inside the parentheses, Form 2, braced bodies with ;, an empty {} body, and a bodyless marker impl.
  • err_trait_eq_body_removed and err_impl_eq_body_removed still match.

Sweep

I parsed every .w file under src, lib, rt, tools, test, examples, build and build.w (3204 files) with ast, once with the installed compiler and once with this stage1. No file uses a shape this change rejects. Every file whose result changed falls into one of two groups:

  • the new fixtures
  • six files that use syntax newer than the installed compiler; they fail under the installed compiler and pass under stage1

rt/fiber_core_windows.w hit the sweep's 30 s timeout under stage1 but passes given more time: the ast renderer is slow on large files, and parsing is not the problem. No UAT fixture or example was touched.

Iterate tier only (:dev plus targeted fixtures). Draft until the seed-driven battery is posted.

…orms (#1346)

parse_trait_decl and parse_impl_block treated ':' as optional punctuation,
skipped newlines, and collected members until one started at column 0, so
an inline first member followed by indented members was one body, and a
bodyless `impl Foo for X` (§2.3) swallowed the indented `fn` lines after it.

Both now name the body form once (parse_decl_body_introducer) and read
member boundaries from it (decl_member_continues):
- Form 1 (':' then content): one member; a second is reported
  ("an inline trait body is a single member ...", fix-it: end the line
  after the header and indent the first member). Newlines inside the
  member's parentheses stay part of it.
- Form 2 (':' ends the line): members indented deeper than the header
  line; nothing indented below is "expected an indented trait body
  after ':'", as for `fn f:`.
- Form 3 (braces): members separated by newlines or semicolons
  (semicolons were rejected before).
- impl/extend with no introducer is bodyless and ends at its newline;
  indented lines after it are reported with the fix-it `impl Foo for X:`.
  Any other token after an impl header is "expected ':' or '{' after
  the impl header" (it used to fall through silently).

Sweep: every .w under src lib rt tools test examples build build.w
parsed with the installed compiler and this stage1; no file changes
verdict except the new fixtures and files that use syntax newer than
the installed compiler.

(cherry picked from commit 7aff486)
(cherry picked from commit 225ea6ed80a74de2a10e312b4fc7e91d61cde028)
@ehartford

Copy link
Copy Markdown
Contributor Author

Batch battery (seed-driven) on main dd786a4 + #1355 → #1357 → #1370 → #1371 as one linear chain (head 45f8aa4): build ok, :fixpoint ok, :test ok (no reds), :test-green ok, :last-green ok. The four PRs are now stacked exactly as tested (each branch = its commit on top of the previous PR); merge in order #1355, #1357, #1370, #1371, retargeting each to main as its parent merges.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 01:03
@ehartford
ehartford merged commit 9631f6c into fix-1349-tuple-pattern-if-subject Sep 23, 2026
ehartford added a commit that referenced this pull request Sep 23, 2026
…nd-chained bases (#1436)

Hand-chained bases stranded #1357 in a dead branch, and squash-merging the
top of a cumulative chain (#1360) landed five PRs as one commit
(2026-09-22). gh stack link creates the stack from staging-worktree
branches without local tracking; gh stack merge lands it all-or-nothing in
order; gh stack rebase replays merged parents with --onto.

Co-authored-by: Eric Hartford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant