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:
17
examples/239-main-signature-reject.sx
Normal file
17
examples/239-main-signature-reject.sx
Normal file
@@ -0,0 +1,17 @@
|
||||
// Entry-point signature gate (ERR step E4.2). `main` must take no parameters
|
||||
// and have a single-slot return: void, an integer (POSIX exit code), or `-> !`
|
||||
// (the error tag rides the single return register). Anything else is a clean
|
||||
// diagnostic — previously `main :: () -> string` SEGFAULTED (the JIT calls main
|
||||
// as `() -> i32`, so a string return is read as garbage). The value-carrying
|
||||
// failable `-> (T, !)` is also rejected for now: its multi-slot return ABI-
|
||||
// mismatches the entry-point call (lands with the E4.2 wrapper). Accepted
|
||||
// shapes are exercised elsewhere (e.g. 238 for integer-exit truncation).
|
||||
// This file is expected to FAIL compilation (exit 1).
|
||||
//
|
||||
// Run: ./zig-out/bin/sx run examples/239-main-signature-reject.sx
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
main :: () -> string { // ERROR: return type must be void, an integer, or `!`
|
||||
return "not an exit code";
|
||||
}
|
||||
Reference in New Issue
Block a user