ww: finish initialization validation parity

This commit is contained in:
2026-08-14 20:03:11 +09:00
parent 25da54936d
commit c59a7c11de
26 changed files with 528 additions and 143 deletions

View File

@@ -1,4 +1,4 @@
//ww:error "#129 A.2 scope"
//ww:run
package main;
type s1t = str;
type s2t = s1t;

View File

@@ -1,10 +1,6 @@
//ww:error "runtime initializer unsupported (alloc/call; rule 7)"
// Module-scope alloc initializer: no DATAW slot exists for a
// runtime-computed global, so pre-reject every reference died at
// LINK time ("undefined reference to 'main.gp'") — the checker now
// rejects at the declaration on both frontends (Hare model:
// ref/harec/src/check.c:4360 rejects non-compile-time-evaluable
// global initializers; ww has no @init path).
//ww:run
// A module-scope allocation is evaluated once by the package task before
// main; its pointer remains live in the zero-backed package variable.
package main;
type box = struct { s: str, n: int };
let gp = alloc(box { s = "hi", n = 1 })!;

View File

@@ -1,7 +1,9 @@
//ww:error "slice-of-{str,slice,tagged} literal static-init unsupported"
//ww:run
package main;
let G: []str = ["aa", "bbb"];
export fn main() i32 = {
if (len(G[0]) != 2) { return 1; };
if (G.len != 2 || G.cap != 2) { return 1; };
if (len(G[0]) != 2) { return 2; };
if (len(G[1]) != 3) { return 3; };
return 0;
};

View File

@@ -1,7 +1,12 @@
//ww:error "repeat with nested-array elements"
// #156/rule-7 carrier: a `...` repeat marker with a nested-array element must
// REJECT on both stages (no consumer needs it; powers_of_ten is fully
// enumerated). From test/wcc/919_array_static_init_run.c nested_ellipsis_reject.
//ww:run
// A fixed outer array gives the nested-row repeat an exact target length.
// Package initialization evaluates the row once and fills every remaining row.
package main;
let A: [4][2]u64 = [[1u64, 2u64]...];
export fn main() i32 = { return 0; };
export fn main() i32 = {
if (A[0][0] != 1 || A[0][1] != 2) { return 1; };
if (A[1][0] != 1 || A[1][1] != 2) { return 2; };
if (A[2][0] != 1 || A[2][1] != 2) { return 3; };
if (A[3][0] != 1 || A[3][1] != 2) { return 4; };
return 0;
};

View File

@@ -1,6 +1,5 @@
//ww:error "runtime initializer unsupported (alloc/call; rule 7)"
// The call sibling of alias_infptr_global's alloc reject: a
// module-scope call initializer has no link-time data either.
//ww:run-exit 7
// A module-scope call initializer executes once in the package task.
package main;
fn mk() i64 = { return 7; };
let gc: i64 = mk();

View File

@@ -1,4 +1,4 @@
//ww:error "slice-of-{str,slice,tagged} literal static-init unsupported"
//ww:run-exit 2
package main;
let g: []str = ["a", "b"];
export fn main() i32 = { return g.len: i32; };

View File

@@ -1,5 +1,12 @@
//ww:error "unsupported variant init"
//ww:run-exit 11
package main;
type u = (int | bool | str);
let g: u = true: u;
export fn main() i32 = { return 0; };
export fn main() i32 = {
match (g) {
case let n: int => return n: i32;
case let b: bool => return 11;
case let s: str => return 22;
};
return 99;
};

View File

@@ -1,5 +1,12 @@
//ww:error "unsupported variant init"
//ww:run-exit 7
package main;
type u = (int | bool | str);
let g: u = 7: u;
export fn main() i32 = { return 0; };
export fn main() i32 = {
match (g) {
case let n: int => return n: i32;
case let b: bool => return 11;
case let s: str => return 22;
};
return 99;
};

View File

@@ -1,4 +1,18 @@
//ww:error "tagged-union array element static-init needs a zero/int payload"
//ww:run-exit 2
package main;
let gs: [2](int | str) = ["hi", 0];
export fn main() int = { return 0; };
export fn main() int = {
match (gs[0]) {
case let n: int => return 10;
case let s: str => {
if (s.len != 2 || s[0] != 104u8 || s[1] != 105u8) {
return 11;
};
};
};
match (gs[1]) {
case let n: int => { if (n != 0) { return 12; }; };
case let s: str => return 13;
};
return 2;
};

View File

@@ -1,5 +1,15 @@
//ww:error "tagged-union struct-field"
//ww:run-exit 2
package main;
type sbox = struct { s: (int | str) };
let g: sbox = sbox { s = "hi" };
export fn main() int = { return 0; };
export fn main() int = {
match (g.s) {
case let n: int => return 10;
case let s: str => {
if (s.len != 2 || s[0] != 104u8 || s[1] != 105u8) {
return 11;
};
};
};
return 2;
};

View File

@@ -1,9 +1,11 @@
//ww:error "slice-of-{str,slice,tagged} literal static-init unsupported"
//ww:run-exit 0
package main;
type ms0 = str;
type ms = ms0;
let G: []ms = ["aa", "bbb"];
export fn main() i32 = {
if (len(G[0]) != 2) { return 1; };
if (G.len != 2 || G.cap != 2) { return 1; };
if (len(G[0]) != 2) { return 2; };
if (len(G[1]) != 3) { return 3; };
return 0;
};

View File

@@ -1,4 +1,4 @@
//ww:error "unsupported element init (int/str literals only; rule 7)"
//ww:run-exit 4
package main;
let g: ((void | size), i64) = (5, 4);
export fn main() i32 = { return g.1: i32; };

View File

@@ -1,4 +1,4 @@
//ww:error "unsupported element init (int/str literals only; rule 7)"
//ww:run
package main;
let g: (f64, i64) = (2.5, 4);
export fn main() i32 = {