Commit 17fcec6
fix(codegen): register struct_layouts for record-type aliases
`type X = { a: T, b: U }` parses as `TopType { td_body = TyAlias
(TyRecord (rfs, _)) }`. The TopType branch in `gen_decl` handled
TyStruct (registering a 4-byte-stride field layout in
`ctx.struct_layouts`) but the TyAlias branch caught everything with
`TyAlias _ -> Ok ctx`, so record aliases never registered.
The downstream symptom is silent: every parameter or return of such
an alias resolves `.field_N` to offset 0 because the layout lookup
returns None. The miscompile only surfaces at runtime via wrong
field values, not a Wasm validation error or a compile failure.
Fix mirrors the existing TyStruct branch but unpacks the alias.
Regression coverage:
- `record-alias registers struct_layouts` — parses
`type State = { health: Int, score: Int };`, calls `gen_decl`
directly, asserts `("State", [("health", 0); ("score", 4)])`
appears in `ctx.struct_layouts`. This test fails on main without
the fix (verified by stash-revert) with
`expected Some [...] but got None`.
- `non-record alias leaves struct_layouts alone` — guards against
accidental over-broadening: `type Plain = Int` must still hit the
catch-all and add no layout entry.
327 → 329 tests; full suite green.
Refs affinescript ASBSQ trial 2026-05-19
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent d1f0e40 commit 17fcec6
2 files changed
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2452 | 2452 | | |
2453 | 2453 | | |
2454 | 2454 | | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
2455 | 2464 | | |
2456 | 2465 | | |
2457 | 2466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
647 | 687 | | |
648 | 688 | | |
649 | 689 | | |
650 | 690 | | |
651 | 691 | | |
652 | 692 | | |
653 | 693 | | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
654 | 698 | | |
655 | 699 | | |
656 | 700 | | |
| |||
0 commit comments