Commit eede831
feat(parser): trait method default bodies (left-factored) (#135 slice 5)
#135 slice 5. `trait_item` had `fn_sig SEMICOLON` (TraitFn) and a whole
`fn_decl` (TraitFnDefault) as separate productions; they share the long
prefix `visibility? FN name params return_type?`, the LR conflict
resolved toward the signature form, so a trait method with a default
body — `pub fn ne(ref self, ref other: Self) -> Bool { ... }` in
stdlib/traits.affine — failed at the `{`.
Fix by left-factoring: parse `fn_sig` once, then branch on SEMICOLON
(→ TraitFn) vs `fn_body` (→ TraitFnDefault built from the sig + body).
The two trait-method forms now differ purely on the next token — the
shared-prefix ambiguity is removed, not papered over. (`ref self`,
sig-only methods, and associated types already worked and are verified
non-regressed.) Trait defaults don't use `total`/`where` (none in
stdlib); those default to false/[].
Effect: traits.affine advances 12 → 124 (cleared 100+ lines; next
blocker is `while let` / `Vec::new()`, a distinct slice-4-class
construct). Two regression tests; full suite green (228).
Advances #135. Refs #128, #135.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a7fdb38 commit eede831
2 files changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
556 | 574 | | |
557 | 575 | | |
558 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3342 | 3342 | | |
3343 | 3343 | | |
3344 | 3344 | | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
3345 | 3366 | | |
3346 | 3367 | | |
3347 | 3368 | | |
| |||
3395 | 3416 | | |
3396 | 3417 | | |
3397 | 3418 | | |
| 3419 | + | |
| 3420 | + | |
3398 | 3421 | | |
3399 | 3422 | | |
3400 | 3423 | | |
| |||
0 commit comments