_offc_probe_i32lit.nx source
↩ module page · 53 lines · 2300 B
1// _offc_probe_i32lit.nx -- ACCEPTANCE PROBE for integer type-context inference.
2//
3// THE DEFECT (routed from the shader-backend lane, 2026-08-24): a bare integer
4// literal types as TY_I64, so `var a: i32 = 0` hands the backend an i64 constant
5// for an i32 binding and cannot lower. They proved it with a ONE-BLOCK control
6// (ir_blocks=1, no branch, no loop), so it is attributable to TYPING and not to
7// control-flow recovery -- and they correctly refused to hack a narrowing into a
8// backend whose own message reads "refused rather than narrowed".
9//
10// THE FIX (staged in nx_parse.nx this lane, NOT yet in the live compiler): the
11// float branch of parse_stmt_let already did exactly this for `let x: f32 = 1.5`
12// -- re-tagging a default-typed literal Value when the binding's declared type
13// demands a narrower one. The integer sibling had never been written. Half a law.
14//
15// HOW TO USE THIS PROBE. It is the before/after harness for that landing:
16// BEFORE the toolchain carries the fix -> this must FAIL TO BUILD (the defect).
17// AFTER the toolchain carries the fix -> this must BUILD and exit 0.
18// A probe that passes on both sides would be proving nothing, so its RED today is
19// the load-bearing half of the evidence.
20//
21// Coverage is every narrowing width and BOTH signednesses, because the fix re-tags
22// with the declared type itself and must therefore preserve the `sext` bit that
23// keeps i32 (sign-extending loads) distinct from u32 (zero-extending) -- a
24// distinction this estate has already paid for once (the x509 0xA0 witness).
25
26import "nx_syscalls.nx"
27
28func main() -> i64 {
29 var a: i32 = 0 // the exact reported case
30 var b: i32 = 7
31 var c: u32 = 7
32 var d: i16 = 7
33 var e: u16 = 7
34 var f: i8 = 7
35 var g: u8 = 7
36
37 // Use every binding so none is optimised away before it is type-checked.
38 var sum: i64 = 0
39 sum = sum + (a as i64)
40 sum = sum + (b as i64)
41 sum = sum + (c as i64)
42 sum = sum + (d as i64)
43 sum = sum + (e as i64)
44 sum = sum + (f as i64)
45 sum = sum + (g as i64)
46
47 if sum != 42 { // 0 + 7*6
48 sys_write(1, "I32LIT FAIL sum mismatch\n" as *u8, 24)
49 return 1
50 }
51 sys_write(1, "I32LIT OK narrow-int literals typed from the binding\n" as *u8, 52)
52 return 0
53}