fix: body-local #run of an unbridged shape fails loudly instead of silent garbage (issue 0182)
The body-local #run fold in emitCall was effectively dead (gated on args.len==0, but the __ct comptime wrapper always carries the implicit *Context arg), so every body-local #run fell through to a RUNTIME call: bridgeable shapes lucked into the right value; an unbridgeable shape (e.g. [2][]i64) ran over --- storage -> garbage, exit 0, no diagnostic. Fold any is_comptime callee (gated !enclosing.is_comptime so nested metatype calls in a comptime wrapper's dead body aren't folded). On a tryEval bail, distinguish a BRIDGE bail (result can't regToValue- materialize -> error: comptime init of 'X' failed: <reason> + comptime_failed, build fails, symmetric with the global #run path) from an EXECUTION bail (VM can't run the body, e.g. NaN/extern -> runtime fallthrough, preserving types/0150), via comptime_vm.last_bail_was_bridge (reset at tryEval entry, set only at regToValue). The const name is threaded onto the wrapper (comptime_display_name) so the diagnostic reads the source name, not __ct_N. Regressions: diagnostics/1204 (negative), comptime/0645 (positive). Verified by 3 adversarial reviews, suite 801/0.
This commit is contained in:
28
examples/comptime/0645-comptime-body-local-run-bridgeable.sx
Normal file
28
examples/comptime/0645-comptime-body-local-run-bridgeable.sx
Normal file
@@ -0,0 +1,28 @@
|
||||
// A body-local `#run` const of a BRIDGEABLE shape — a scalar, a struct, an
|
||||
// array, or an `?Array` optional — evaluates and produces its const value.
|
||||
// These are the common cases that must keep working alongside the issue-0182
|
||||
// fix (which fails ONLY the unbridgeable-result case, e.g. `[2][]i64`).
|
||||
//
|
||||
// Regression (issue 0182): the body-local `#run` fold must not regress the
|
||||
// bridgeable cases when it learned to fail loudly on an unbridgeable result.
|
||||
#import "modules/std.sx";
|
||||
|
||||
Pt :: struct { x: i64; y: i64; }
|
||||
|
||||
mk_scalar :: () -> i64 { return 42; }
|
||||
mk_struct :: () -> Pt { return .{ x = 3, y = 4 }; }
|
||||
mk_arr :: () -> [3]i64 { r : [3]i64 = ---; r[0] = 10; r[1] = 20; r[2] = 30; return r; }
|
||||
mk_opt :: () -> ?[3]i64 { r : [3]i64 = ---; r[0] = 1; r[1] = 2; r[2] = 3; return r; }
|
||||
|
||||
main :: () {
|
||||
N :: #run mk_scalar();
|
||||
S :: #run mk_struct();
|
||||
A :: #run mk_arr();
|
||||
O :: #run mk_opt();
|
||||
|
||||
print("N={}\n", N);
|
||||
print("S={} {}\n", S.x, S.y);
|
||||
print("A={} {} {}\n", A[0], A[1], A[2]);
|
||||
v := O!;
|
||||
print("O={}\n", v[1]);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
N=42
|
||||
S=3 4
|
||||
A=10 20 30
|
||||
O=2
|
||||
Reference in New Issue
Block a user