ERR/E4.2: entry-point signature gate for main

Add validateMainSignature (lowerRoot Pass 4a). main must take no parameters
and have a single-slot return — void, an integer (POSIX exit code), or `-> !`
/ `-> !Named` (the error tag rides the single return register, which the JIT's
`() -> i32` main call handles directly). Other shapes are now clean
diagnostics instead of silent miscompiles:

- `main :: () -> string` previously SEGFAULTED (the i32 return register was
  read as a string) — now a clear "return type must be void, an integer, or
  `!`" error.
- `main :: (x: ...)` previously ran silently (param ignored) — now rejected.
- `main :: () -> f64` / non-failable tuple / etc. — rejected.

The value-carrying failable `-> (T, !)` is rejected for now: its multi-slot
{value, error} return ABI-mismatches the entry-point call and segfaults. That
shape needs the E4.2 entry-point wrapper (gated on E3 return traces); rejecting
loudly beats miscompiling. `-> !` (no value) IS accepted — single-slot, works
today (success exits 0; a raise exits nonzero, trace/tag story pending E3).

examples/239-main-signature-reject.sx covers the `-> string` rejection (exit 1).
Accepted shapes are exercised elsewhere (238 for integer-exit truncation; the
existing suite for void/int main). Gates: zig build, zig build test, bash
tests/run_examples.sh (276 passed; lone failure is the user's uncommitted
213-canonical-map pack WIP).
This commit is contained in:
agra
2026-06-01 07:23:31 +03:00
parent 94335f94d7
commit 6e32e6c63c
4 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,5 @@
error: main: return type must be void, an integer, or `!`; got 'string'
--> /Users/agra/projects/sx/examples/239-main-signature-reject.sx:15:15
|
15 | main :: () -> string { // ERROR: return type must be void, an integer, or `!`
| ^^^^^^