Commit bd649ef
Add dedicated test coverage for root-level code with no function main() (#294)
* Add tests for plain function and type alias cross-module exports/imports
* Add dedicated test coverage for root-level code with no function main()
When a file has no explicit main(), generateGlobalEntryCode
(MLIRGenModule.cpp) gathers every statement not inside a function/class body
and compiles it AS the synthesized main() itself. ~54 existing test files
incidentally rely on this (root-level assert/print calls with no main
wrapper), but they're all short/simple - none deliberately exercised control
flow at true root scope. 44toplevelcode.ts has top-level declarations but
still wraps its actual test logic in an explicit main().
Also notable: a `let`/`const` declared directly at root level is module-scope
storage (like a static field), not a stack local - a real difference from
the normal case worth covering, especially for closures capturing it.
Added:
- 00toplevel_control_flow.ts: for/while/switch/try-catch-finally running
directly at root scope, a closure capturing a root-level `let`, and a
class defined and used at root (instantiated, method called).
- 00toplevel_no_main_with_helpers.ts: root-level statements coexisting with
ordinary function/class declarations, calling into them.
Registered in both compile and jit tiers (4 new add_test entries), next to
the existing 44toplevelcode.ts registration.
Investigation note: hit what looked like a real bug along the way - JIT
crashed with an uncaught C++ exception on the try/catch block, AOT produced
no output at all. Root cause was in the test, not the compiler: `throw 42;`
throws an integer literal, but `catch (v: number)` expects `number` (f64),
and catch-by-type requires an exact type match - the exception propagated
uncaught. Fixed to `throw 42.0;`, matching the established idiom in
00try_catch.ts's main2(), and confirmed passing in both tiers before adding.
827/827 tests green (823 + these 4 new entries).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 30efabc commit bd649ef
3 files changed
Lines changed: 111 additions & 0 deletions
File tree
- tslang/test/tester
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
428 | 435 | | |
429 | 436 | | |
430 | 437 | | |
| |||
793 | 800 | | |
794 | 801 | | |
795 | 802 | | |
| 803 | + | |
| 804 | + | |
796 | 805 | | |
797 | 806 | | |
798 | 807 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments