Repository navigation
Commit 4ee0e22
committed
fix: module flattening, Bun-ESM match lowering and loader follow-ups to #788
Review follow-ups to #788, which merged before they were pushed.
Module loader and flattening:
- Private helpers carried into a flattened program are renamed
`__priv_<Module>__<name>` by a capture-avoiding substitution
(`Ast.rename_free`), so two modules with a same-named private helper
(kyq's two `parse_int`s) no longer collide. A remaining collision is a
loud error, not a silent pick.
- Nested candidates are searched in every directory before any
parent-module fallback; a failed load clears its loading marker, so a
later import is not reported as a cycle.
- An aliased import emits the original binding before the alias, in
declaration order; free-variable analysis covers record shorthand and
spread.
- Only the root program's `main` is run by `eval`; the module root is
normalised and the source directory is searched.
Bun-ESM backend:
- Match is lowered as a labelled block, so guards see the arm's
bindings and a `return` in an arm leaves the function.
- `let _ = e` still evaluates `e`; temporaries are fresh per lowering.
- A `return` in an `if` condition, a scrutinee or a guard is refused
loudly instead of being miscompiled.
Interpreter: the untypeable Char-ordering arms are removed.
Docs: the module-loader holes are renumbered H20-H22 -> H23-H25 in
docs/COMPLETION-PLAN.adoc, because #787 assigned H20-H22 to the
proof-review holes; H2, H23 and H24 record the round-2 fixes.
Tests: test/test_module_root_flatten.ml (22 cases). Disabling
qualification, the two-phase search, alias ordering, wildcard lowering
or the marker clear each makes a test fail. Full suite: no failures
beyond the 33 pre-existing walker-* tests (they need the tree-sitter
CLI; same count on main). kyq parser and lint drivers: 20/20 under Bun.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P4yFkxW5Heb8p2YW7ZYs9F1 parent aea7de8 commit 4ee0e22
7 files changed
Lines changed: 609 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
180 | 179 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 180 | | |
187 | 181 | | |
188 | 182 | | |
189 | 183 | | |
190 | 184 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
| |||
328 | 326 | | |
329 | 327 | | |
330 | 328 | | |
331 | | - | |
| 329 | + | |
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
| |||
378 | 376 | | |
379 | 377 | | |
380 | 378 | | |
381 | | - | |
| 379 | + | |
382 | 380 | | |
383 | 381 | | |
384 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
224 | | - | |
225 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
535 | 545 | | |
536 | 546 | | |
537 | 547 | | |
| |||
566 | 576 | | |
567 | 577 | | |
568 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 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 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
569 | 700 | | |
570 | 701 | | |
571 | 702 | | |
| |||
659 | 790 | | |
660 | 791 | | |
661 | 792 | | |
662 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
663 | 797 | | |
664 | 798 | | |
665 | | - | |
| 799 | + | |
| 800 | + | |
666 | 801 | | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
667 | 805 | | |
668 | 806 | | |
669 | 807 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1906 | 1906 | | |
1907 | 1907 | | |
1908 | 1908 | | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
1909 | 1913 | | |
1910 | 1914 | | |
1911 | 1915 | | |
1912 | 1916 | | |
1913 | 1917 | | |
1914 | 1918 | | |
1915 | 1919 | | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
1916 | 1927 | | |
1917 | | - | |
1918 | | - | |
1919 | | - | |
1920 | | - | |
1921 | | - | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
1925 | | - | |
1926 | | - | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
1927 | 1944 | | |
1928 | | - | |
1929 | | - | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
1930 | 1948 | | |
1931 | 1949 | | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
1932 | 1957 | | |
1933 | 1958 | | |
1934 | 1959 | | |
| |||
1966 | 1991 | | |
1967 | 1992 | | |
1968 | 1993 | | |
1969 | | - | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
1970 | 2000 | | |
1971 | 2001 | | |
1972 | 2002 | | |
| |||
1978 | 2008 | | |
1979 | 2009 | | |
1980 | 2010 | | |
1981 | | - | |
| 2011 | + | |
1982 | 2012 | | |
1983 | 2013 | | |
1984 | 2014 | | |
| |||
0 commit comments