fix(diagnostics): reject reserved type-name bindings in every module (issue 0077)

The issue-0076 reserved-type-name binding diagnostic only ran over main-file
decls, so an imported module (or the stdlib) could still declare `s2 := ...`
and reach lowering, where the address-of family loads the whole aggregate and
passes it by value to a `ptr` param — LLVM verifier abort.

Extend coverage to every compiled module: a dedicated `checkBindingNames` walk
(in semantic_diagnostics.zig) visits every var/`:=`/typed-local binding name and
function/lambda/struct-method parameter at any depth, with NO main-file filter,
descending the `namespace_decl` that a `mod :: #import` wraps so imported-module
decls are reached. It tracks each module's source_file (save/restore per node)
so the diagnostic renders against the imported module's text. Rejection still
defers to the parser's `Type.fromName` classifier; the unknown-type check (0064)
stays main-file-only. No lowering special-case; `.identifier`-only address-of
paths are unchanged.

Stdlib audit: the only reserved-name bindings under library/ were two `u1`
locals in ui/renderer.sx (UV coords) — renamed to u_min/u_max/v_min/v_max.

Regression test: examples/1120-diagnostics-imported-reserved-type-name.sx (+
companion mod.sx) — an imported `s2 := ...` now emits the clean diagnostic at
the import's declaration site (exit 1), not an LLVM abort.

Resolves issues 0076 (coverage extension) and 0077.
This commit is contained in:
agra
2026-06-03 19:32:49 +03:00
parent f49a49cd07
commit df6e830bec
9 changed files with 301 additions and 30 deletions

View File

@@ -198,17 +198,17 @@ UIRenderer :: struct {
w := frame.size.width;
h := frame.size.height;
u0 := uv_min.x;
v0 := uv_min.y;
u1 := uv_max.x;
v1 := uv_max.y;
u_min := uv_min.x;
v_min := uv_min.y;
u_max := uv_max.x;
v_max := uv_max.y;
self.write_vertex(x0, y0, u0, v0, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y0, u1, v0, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x0, y1, u0, v1, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y0, u1, v0, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y1, u1, v1, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x0, y1, u0, v1, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x0, y0, u_min, v_min, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y0, u_max, v_min, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x0, y1, u_min, v_max, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y0, u_max, v_min, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x1, y1, u_max, v_max, r, g, b, a, radius, border_w, w, h);
self.write_vertex(x0, y1, u_min, v_max, r, g, b, a, radius, border_w, w, h);
}
write_vertex :: (self: *UIRenderer, x: f32, y: f32, u: f32, v: f32, r: f32, g: f32, b: f32, a: f32, cr: f32, bw: f32, rw: f32, rh: f32) {
@@ -377,10 +377,10 @@ UIRenderer :: struct {
gx1 := gx0 + cached.width * inv_dpi;
gy1 := gy0 + cached.height * inv_dpi;
u0 := cached.uv_x;
v0 := cached.uv_y;
u1 := cached.uv_x + cached.uv_w;
v1 := cached.uv_y + cached.uv_h;
u_min := cached.uv_x;
v_min := cached.uv_y;
u_max := cached.uv_x + cached.uv_w;
v_max := cached.uv_y + cached.uv_h;
if self.vertex_count + 6 > MAX_UI_VERTICES {
@@ -389,12 +389,12 @@ UIRenderer :: struct {
// corner_radius = -1.0 signals "text mode" to the fragment shader
neg1 : f32 = 0.0 - 1.0;
self.write_vertex(gx0, gy0, u0, v0, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy0, u1, v0, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx0, gy1, u0, v1, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy0, u1, v0, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy1, u1, v1, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx0, gy1, u0, v1, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx0, gy0, u_min, v_min, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy0, u_max, v_min, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx0, gy1, u_min, v_max, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy0, u_max, v_min, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx1, gy1, u_max, v_max, r, g, b, a, neg1, 0.0, 0.0, 0.0);
self.write_vertex(gx0, gy1, u_min, v_max, r, g, b, a, neg1, 0.0, 0.0, 0.0);
}
}
i += 1;