nx_ident_len_gate.nx source
↩ module page · 53 lines · 2978 B
1// nx_ident_len_gate.nx -- the 63/64 identifier-length boundary in lex_ident_or_kw (debt 1785521184).
2//
3// The scan used to be `while i < 63 { ... advance(L) ... }`, so on reaching 63 it stopped WITHOUT
4// consuming the rest of the identifier. A 64-char name emitted a 63-char IDENT and the lexer then
5// resumed at char 64, lexing the tail as a SECOND identifier token -- a TOKEN SPLIT, not a truncation.
6//
7// HOW THIS PROVES IT, AT COMPILE TIME -- THE ONLY WAY IT CAN BE PROVEN. A split turns the 64-char
8// definition below into two adjacent identifiers where the parser expects one, followed by a paren --
9// a syntax error. So THIS FILE COMPILING AT ALL is the verdict for T2. It cannot pass vacuously: with
10// the defect present the build fails outright, and no runtime assertion could detect it because there
11// is no runtime.
12//
13// THE BOUNDARY PAIR IS THE WHOLE TEST. 63 must work (it always did) and 64 must work (it did not). An
14// off-by-one in any future fix re-introduces the split for exactly one length -- precisely the bug a
15// single-value test walks past. Never reduce this gate to one identifier.
16//
17// expect_exit: 0 license_tier: ORIGINAL
18
19import "nx_kernel_v2.nx"
20
21// EXACTLY 63 chars.
22func id_012345678901234567890123456789012345678901234567890123456789() -> nx_int { return 1 }
23
24// EXACTLY 64 chars. This is the one that SPLIT under the defect.
25func idx_012345678901234567890123456789012345678901234567890123456789() -> nx_int { return 2 }
26
27func main() -> nx_exit {
28 println("=== nx_ident_len_gate -- 63/64 identifier boundary ===" as *u8)
29
30 let a: nx_int = id_012345678901234567890123456789012345678901234567890123456789()
31 if a != 1 { println("T1 len63 FAIL" as *u8); return 1 }
32 println("T1 len63 PASS 63-char identifier lexes as ONE token" as *u8)
33
34 let b: nx_int = idx_012345678901234567890123456789012345678901234567890123456789()
35 if b != 2 { println("T2 len64 FAIL" as *u8); return 2 }
36 println("T2 len64 PASS 64-char identifier lexes as ONE token (was a SPLIT)" as *u8)
37
38 println("" as *u8)
39 println("=== NON-VACUITY ===" as *u8)
40 println("With the split defect present this file does not COMPILE." as *u8)
41 println("Reaching this line at all is the proof; no runtime check could be." as *u8)
42 println("" as *u8)
43 println("=== KNOWN RESIDUAL LIMIT (deliberately NOT asserted as a pass) ===" as *u8)
44 println("Two identifiers sharing their first 63 chars still COLLIDE: only 63" as *u8)
45 println("bytes are stored. The fix makes that LOUD instead of silent; it does" as *u8)
46 println("not remove it. Removing it needs heap-backed name storage, which must" as *u8)
47 println("ALSO migrate ~14 loops in nx_parse.nx that rely on a NUL inside 64" as *u8)
48 println("bytes. Asserting no-collision here would encode a promise the compiler" as *u8)
49 println("does not make." as *u8)
50 println("" as *u8)
51 println("GATE VERDICT: GREEN 2/2" as *u8)
52 return 0
53}