Files
ww/test/wcc/data/dotfield_slice_defhi_global/case.ww
Hojun-Cho 66251cc52b cgen: default the hi bound of a slice/str-field slice, both stages
x.slicefield[:] / x.strfield[2:] emitted MOVQ $0 for the omitted hi
bound on BOTH stages (N_IDENT-gated dispatch; symmetric, so byte
identity never caught it) in all four sites: cgexpr N_SLICE + pushargs
(cstage), cgslice + pushargsrev (wwstage). The new arm re-evaluates
the pure field read for its {ptr,len,cap} header and takes .len,
covering local, viaptr, dot-chain, (*p), arr[i], and global inners.
Call inners still loud-reject upstream. Sibling of the #252/#257
array-field arms.
2026-08-08 00:29:51 +09:00

52 lines
1.1 KiB
Plaintext

//ww:run
// Default-hi slice of a slice/str FIELD on module-GLOBAL struct
// bases (single dot and chain), expression + arg positions — the
// global leg of dotfield_slice_defhi.
package main;
type inner = struct {
buf: []i32,
name: str,
};
type outer = struct {
pad: i64,
in: inner,
};
let g: inner = inner{};
let go: outer = outer{};
fn sum(xs: []i32) i32 = {
let t: i32 = 0;
let i: i32 = 0;
for (i < len(xs)) {
t += xs[i];
i += 1;
};
return t;
};
export fn main() int = {
let arr: [4]i32 = [10, 20, 30, 40];
g.buf = arr[:];
g.name = "globals";
let b1: []i32 = g.buf[:];
if (len(b1) != 4) { return 1; };
let b2: []i32 = g.buf[2:];
if (len(b2) != 2) { return 2; };
if (b2[0] != 30) { return 3; };
let s1: str = g.name[3:];
if (len(s1) != 4) { return 4; };
if (sum(g.buf[:]) != 100) { return 5; };
if (sum(g.buf[1:]) != 90) { return 6; };
go.in.buf = arr[:];
go.in.name = "chain";
let b3: []i32 = go.in.buf[:];
if (len(b3) != 4) { return 7; };
if (sum(go.in.buf[2:]) != 70) { return 8; };
let s2: str = go.in.name[1:];
if (len(s2) != 4) { return 9; };
return 0;
};