test: migrate 989_letshadow to @test value pin, retire C twin (fold-3)

#152 link-the-let-before-its-init miscompile (miscompiled IDENTICALLY on both stages, so byte-id 990-997 was blind; only a runtime value check catches it). Lifted the run fixture into test/lang/letshadow_test.ww (primitive @test value pin; byteid-eligible — symmetric, cs==ww). byteid floor 56->57. Closes the fold-3 #7 umbrella (last C test twin retired).
This commit is contained in:
2026-06-22 18:30:04 +09:00
parent 9cef92175f
commit 99b98b9b1b
3 changed files with 23 additions and 76 deletions

View File

@@ -1,19 +1,13 @@
// letshadow — #152 regression pin. A `let` binding must NOT be visible
// during its OWN initializer: `let x = f(x)` evaluates f(x) in the OUTER
// scope (Hare: harec check.c clet runs cexpr before scope_define). Both
// stages once linked the binding into the cgen localfind chain BEFORE
// emitting the init, so the init read the fresh UNINIT shadow slot — a
// silent miscompile identical on both stages (byte-id GREEN over it), so
// this is a RUNTIME assertion. Signalled-then-exit(+10) pinpoints the row.
// letshadow_test — #152 regression pin, migrated from test/wcc/989_letshadow_run.c.
//
// Run with `out/bin/ww run test/wcc/989_letshadow.ww`; exit 0 = all pass.
// A `let` binding must NOT be visible during its OWN initializer:
// `let x = f(x)` evaluates f(x) in the OUTER scope (Hare: harec check.c clet
// runs cexpr before scope_define). Both stages once linked the binding into
// the cgen localfind chain BEFORE emitting the init, so the init read the
// fresh UNINIT shadow slot — a silent miscompile IDENTICAL on both stages
// (byte-id was GREEN over it), now fixed. PRIMITIVE-only (i32) asserts.
package main;
import os;
let signalled: i32 = 0;
fn fail() void = { os.exit(signalled + 10); };
package letshadow_test;
fn id(s: str) str = { return s; };
@@ -60,10 +54,18 @@ fn arrlitselfref() i32 = {
return r;
};
export fn main() i32 = {
signalled = 1; if (paramshadow("hello") != 604) { fail(); };
signalled = 2; if (letinletinit() != 6) { fail(); };
signalled = 3; if (renamecontrol("hi") != 2) { fail(); };
signalled = 4; if (arrlitselfref() != 6) { fail(); };
return 0;
@test fn param_self_shadow() void = {
assert(paramshadow("hello") == 604i32);
};
@test fn let_in_let_init() void = {
assert(letinletinit() == 6i32);
};
@test fn rename_control() void = {
assert(renamecontrol("hi") == 2i32);
};
@test fn arrlit_self_ref() void = {
assert(arrlitselfref() == 6i32);
};

View File

@@ -1,50 +0,0 @@
/*
* 989_letshadow_run — #152 regression pin. Compile + run the letshadow
* fixture under the C-side `ww run` driver (cstage w6c) and assert exit 0.
*
* The bug (link-the-let-before-its-init) miscompiled IDENTICALLY on both
* stages, so byte-id 990-997 is blind to it; only a runtime value check
* catches the regression. Same thin-wrapper shape as 989_path_run.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
static int
runwait(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return 1;
}
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[1024];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
bin = absbin;
}
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
const char *src = "test/wcc/989_letshadow.ww";
char path[1024], cmd[2048];
snprintf(path, sizeof path, "%s/%s", cwd, src);
snprintf(cmd, sizeof cmd, "%s/ww run %s", bin, path);
int rc = runwait(cmd);
if (rc != 0) {
fprintf(stderr, "letshadow_run FAIL: %s exited %d "
"(row %d miscompiled — #152)\n", src, rc, rc - 10);
return 1;
}
printf("letshadow_run: %s ok\n", src);
return 0;
}