// #5 alias arc F2b (B6 train): the cgen.c cgexpr/cgstmt // INLINE single-peel sweep through type_chase_named, by consumer family — // c1 assign/reassign, c2 call-arg, c3 addr-of/field-walk/index spine, // c4 cast/is/try, c5 reads/len/globals. Every K_RUN row was a cs-side // single-peel that left a 2-level alias TY_NAMED (or ww the alias-blind side // at the c3 index/field gates, graduated by W2 #102): silent-wrong store // width, wrong stride, alias-blind field offset. Migrated from // test/wcc/944_alias_cgen_b6_run.c (#5-C3). // // The 3 K_BUILDERR/loud rows (fsarg0_loud_ctl, fsarg2_bound, try_loud_38b) // live elsewhere — value rows only here. Per-row type/global/fn families are // prefixed to dedup the source's reused {ms,st,fs,u,big,S,my32,...} spellings // at module scope (ww forbids local `type`); forward-ref decl order is // irrelevant to value semantics here so families are declared base-first. package alias_cgen_b6_test; type c1sr_ms0 = str; type c1sr_ms = c1sr_ms0; @test fn streassign_2lvl() void = { let a: c1sr_ms = "hello"; let b: c1sr_ms = "x"; b = a; assert(len(b) == 5); }; type c1ra_st0 = struct { a: i64, b: i64, c: i64 }; type c1ra_st = c1ra_st0; @test fn sreassign_2lvl() void = { let x: c1ra_st; x.a = 1; x.b = 2; x.c = 3; let y: c1ra_st; y.a = 0; y.b = 0; y.c = 0; y = x; assert(y.c == 3 && y.b == 2); }; type c1da_st0 = struct { a: i64, b: i64 }; type c1da_st = c1da_st0; @test fn dassign_2lvl() void = { let x: c1da_st; x.a = 1; x.b = 2; let p: *c1da_st = &x; (*p).b = 9; assert(x.b == 9); }; type c2fi_fs0 = struct { x: f64 }; type c2fi_fs = c2fi_fs0; fn c2fi_mk() c2fi_fs0 = { let s: c2fi_fs0; s.x = 2.5; return s; }; fn c2fi_g(p: c2fi_fs) f64 = { return p.x; }; @test fn fsarg_ident_ctl() void = { let v: c2fi_fs = c2fi_mk(); assert(c2fi_g(v) == 2.5); }; type c2sa_big0 = struct { a: i64, b: i64, c: i64 }; type c2sa_big = c2sa_big0; fn c2sa_g(p: c2sa_big) i64 = { return p.a + p.c; }; @test fn sarg_2lvl() void = { let s: c2sa_big; s.a = 4; s.b = 5; s.c = 9; assert(c2sa_g(s) == 13); }; type c2st_ms0 = str; type c2st_ms = c2st_ms0; fn c2st_g(s: c2st_ms) i64 = { return len(s): i64; }; @test fn strarg_2lvl() void = { let a: c2st_ms = "hello"; assert(c2st_g(a) == 5); }; type c3if_el0 = struct { a: i64, b: i64 }; type c3if_el = c3if_el0; // graduated: #102 (W2) @test fn idxf_2lvl() void = { let xs: [2]c3if_el; xs[0].a = 1; xs[0].b = 2; xs[1].a = 3; xs[1].b = 4; assert(xs[1].b == 4 && xs[0].b == 2); }; type c3ifp_el0 = struct { a: i64, b: i64 }; @test fn idxf_plain_ctl() void = { let xs: [2]c3ifp_el0; xs[0].a = 1; xs[0].b = 2; xs[1].a = 3; xs[1].b = 4; assert(xs[1].b == 4 && xs[0].b == 2); }; type c3af_st0 = struct { a: i64, b: i64 }; type c3af_st = c3af_st0; // graduated: #102 (W2) @test fn ampf_2lvl() void = { let x: c3af_st; x.a = 1; x.b = 2; let p: *c3af_st = &x; let q: *i64 = &p.b; *q = 9; assert(x.b == 9); }; type c3afp_st0 = struct { a: i64, b: i64 }; @test fn ampf_plain_ctl() void = { let x: c3afp_st0; x.a = 1; x.b = 2; let p: *c3afp_st0 = &x; let q: *i64 = &p.b; *q = 9; assert(x.b == 9); }; type c3av_st0 = struct { a: i64, b: i64 }; type c3av_st = c3av_st0; // amendment: #102 (W2) @test fn ampv_2lvl() void = { let x: c3av_st; x.a = 1; x.b = 2; let q: *i64 = &x.b; *q = 9; assert(x.b == 9); }; type c3avp_st0 = struct { a: i64, b: i64 }; @test fn ampv_plain_ctl() void = { let x: c3avp_st0; x.a = 1; x.b = 2; let q: *i64 = &x.b; *q = 9; assert(x.b == 9); }; type c3cd_in0 = struct { v: i64 }; type c3cd_in1 = c3cd_in0; type c3cd_out0 = struct { inner: c3cd_in1, n: i64 }; type c3cd_out1 = c3cd_out0; @test fn chdot_2lvl() void = { let s: c3cd_out1; s.inner.v = 7; s.n = 3; let p: *c3cd_out1 = &s; assert(p.inner.v == 7); }; type c3es_my32 = u32; type c3es_my32b = c3es_my32; @test fn esub_2lvl() void = { let xs: [3]c3es_my32b; xs[0] = 5; xs[1] = 6; xs[2] = 7; assert(xs[0]: i64 + xs[1]: i64 + xs[2]: i64 == 18); }; type c3kw_my32 = u32; type c3kw_my32b = c3kw_my32; type c3kw_S = struct { arr: [3]c3kw_my32b, tail: int }; @test fn kw1_101() void = { let s = c3kw_S { arr = [10u32, 20u32, 30u32], tail = 77 }; assert(size(c3kw_my32b) == 4); assert(s.arr[0] == 10u32); assert(s.arr[1] == 20u32); assert(s.arr[2] == 30u32); assert(s.tail == 77); }; type c3kc_my16 = u16; type c3kc_S2 = struct { arr: [4]c3kc_my16, n: int }; @test fn kw1_ctl16() void = { let s = c3kc_S2 { arr = [1u16, 2u16, 3u16, 4u16], n = 9 }; assert(s.arr[0] + s.arr[1] + s.arr[2] + s.arr[3] == 10u16); assert(s.n == 9); }; type c4sc_ms0 = str; type c4sc_ms = c4sc_ms0; @test fn strcast_2lvl() void = { let a: c4sc_ms = "hey"; let b: []u8 = a: []u8; assert(len(b) == 3); assert(b[0] == 'h'); }; type c4ic_u0 = (void | i64); type c4ic_u = c4ic_u0; @test fn idcast_2lvl() void = { let v: c4ic_u = 42i64; let w: c4ic_u = (v: c4ic_u); match (w) { case let n: i64 => { assert(n == 42); }; case void => { assert(false); }; }; }; type c4is_u0 = (void | i64); type c4is_u = c4is_u0; @test fn is_2lvl() void = { let v: c4is_u = 42i64; assert(v is i64); assert(!(v is void)); }; type c5tf_u0 = (void | i64); type c5tf_u = c5tf_u0; type c5tf_st0 = struct { f: c5tf_u, n: i64 }; type c5tf_st = c5tf_st0; @test fn tfread_2lvl() void = { let s: c5tf_st; s.f = 42i64; s.n = 3; assert(s.f is i64); let p: *c5tf_st = &s; assert(p.f is i64); }; type c5ln_ms0 = str; type c5ln_ms = c5ln_ms0; type c5ln_ar0 = [4]i64; type c5ln_ar = c5ln_ar0; @test fn len_2lvl() void = { let a: c5ln_ms = "hello"; assert(len(a) == 5); let xs: c5ln_ar = [1, 2, 3, 4]; assert(len(xs) == 4); }; type c5gr_my64 = i64; type c5gr_my64b = c5gr_my64; let c5gr_G: c5gr_my64b = 7; @test fn gref_2lvl() void = { assert(c5gr_G == 7); }; type c5mr_big = struct { a: i64, b: i64, c: i64, d: i64, e: i64 }; type c5mr_m0 = (void | c5mr_big); type c5mr_m = c5mr_m0; @test fn memread_40b() void = { let s: c5mr_big; s.a = 1; s.b = 2; s.c = 3; s.d = 4; s.e = 55; let v: c5mr_m = s; assert(v is c5mr_big); match (v) { case let w: c5mr_big => { assert(w.e == 55); }; case void => { assert(false); }; }; };