diff --git a/examples/1137-diagnostics-value-param-type-fn-no-cascade.sx b/examples/1137-diagnostics-value-param-type-fn-no-cascade.sx new file mode 100644 index 0000000..4ae3cfb --- /dev/null +++ b/examples/1137-diagnostics-value-param-type-fn-no-cascade.sx @@ -0,0 +1,27 @@ +// A FAILED value-param bind on a type-RETURNING FUNCTION must emit exactly its +// own diagnostic and NOT cascade a bogus `field '…' not found on ''` when the +// binding is later field-accessed. The type-fn binder must poison the binding to +// `.unresolved` (the diagnosed-poison sentinel) — exactly like the struct binder — +// so the downstream `.len` is suppressed, not reported as a second error. +// +// Regression (issue 0083): the type-fn path (`instantiateTypeFunction`) fell +// through to an empty-struct placeholder named after the function on a failed +// value-param bind, so `a.len` produced a second `field 'len' not found on +// 'MakeC'` error. The struct binder already returned `.unresolved` here; the +// type-fn binder now matches it. Three failure modes, three clean diagnostics, +// zero field cascades: +// - value-param overflow via an aliased integer constraint (`$K: Count`), +// - a non-const value-param arg (`get()`), +// - an unknown TYPE arg (`NoSuchType`) — must still report the unknown type. +#import "modules/std.sx"; + +Count :: u32; +MakeC :: ($K: Count, $T: Type) -> Type { return [K]T; } +get :: () -> u32 { return 4; } + +main :: () { + a : MakeC(5000000000, s64) = ---; + b : MakeC(get(), s64) = ---; + c : MakeC(3, NoSuchType) = ---; + print("unreachable {} {} {}\n", a.len, b.len, c.len); +} diff --git a/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.exit b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.exit @@ -0,0 +1 @@ +1 diff --git a/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stderr b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stderr new file mode 100644 index 0000000..06633c5 --- /dev/null +++ b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stderr @@ -0,0 +1,17 @@ +error: unknown type 'NoSuchType' + --> examples/1137-diagnostics-value-param-type-fn-no-cascade.sx:25:18 + | +25 | c : MakeC(3, NoSuchType) = ---; + | ^^^^^^^^^^ + +error: value 5000000000 does not fit in u32 parameter K + --> examples/1137-diagnostics-value-param-type-fn-no-cascade.sx:23:15 + | +23 | a : MakeC(5000000000, s64) = ---; + | ^^^^^^^^^^ + +error: generic value parameter 'K' must be a compile-time integer constant + --> examples/1137-diagnostics-value-param-type-fn-no-cascade.sx:24:15 + | +24 | b : MakeC(get(), s64) = ---; + | ^^^^^ diff --git a/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stdout b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stdout new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/expected/1137-diagnostics-value-param-type-fn-no-cascade.stdout @@ -0,0 +1 @@ + diff --git a/issues/0083-named-const-array-dimension-miscompiled.md b/issues/0083-named-const-array-dimension-miscompiled.md index 2b4ae7c..97ff9ef 100644 --- a/issues/0083-named-const-array-dimension-miscompiled.md +++ b/issues/0083-named-const-array-dimension-miscompiled.md @@ -195,6 +195,23 @@ > u32 + s8 overflow), `examples/1136-diagnostics-array-dim-nonconst-direct-no-crash.sx` > (direct non-const dim halts cleanly, no fabrication / panic); the cascade > cleanup also tightened `examples/1502`/`1503` to one diagnostic each. +> +> **Final convergence — type-fn binder parity (attempt 10).** One last cell of +> the count surface still diverged from the struct binder. A FAILED value-param +> bind on a type-RETURNING FUNCTION (`MakeC :: ($K: Count, $T: Type) -> Type +> { return [K]T; }`; `a : MakeC(5_000_000_000, s64)`) emitted its correct range +> diagnostic, but `instantiateTypeFunction` then returned `null`, so +> `resolveParameterizedWithBindings` fell through to the empty-struct *placeholder* +> named `MakeC`. The binding `a` got that placeholder type, so a downstream +> `a.len` cascaded a bogus second error `field 'len' not found on type 'MakeC'`. +> The struct binder (`instantiateGenericStruct`) already returned `.unresolved` +> here; the type-fn binder now matches it — the failed value-param bind poisons to +> `.unresolved` instead of `null`, so the caller propagates the diagnosed poison +> and the existing `emitFieldError` suppression yields ONE clean diagnostic. Covers +> every type-fn value-param failure mode (overflow via aliased constraint, +> non-const arg, unknown type arg). Files: `src/ir/lower.zig` (one line in +> `instantiateTypeFunction`). Regression: +> `examples/1137-diagnostics-value-param-type-fn-no-cascade.sx`. ## Symptom A fixed array whose dimension is a module-global integer constant (`N :: 16; diff --git a/src/ir/lower.zig b/src/ir/lower.zig index 5d40114..ddb0210 100644 --- a/src/ir/lower.zig +++ b/src/ir/lower.zig @@ -12183,9 +12183,14 @@ pub const Lowering = struct { name_parts.appendSlice(self.alloc, tname) catch {}; } else { // Value param (e.g., $N: u32) — fold to a compile-time integer - // and range-check against its declared type. + // and range-check against its declared type. A failed bind has + // already diagnosed itself, so poison to `.unresolved` rather + // than `null`: `null` makes the caller fall through to the + // empty-struct placeholder named after the fn, which then + // cascades a bogus `field not found` on any later access. The + // struct binder (`instantiateGenericStruct`) poisons the same way. const vp_type: ?[]const u8 = if (tp.constraint.data == .type_expr) tp.constraint.data.type_expr.name else null; - const val = self.resolveValueParamArg(args[i], tp.name, vp_type) orelse return null; + const val = self.resolveValueParamArg(args[i], tp.name, vp_type) orelse return .unresolved; cvb.put(tp.name, val) catch {}; var val_buf: [32]u8 = undefined; const val_str = std.fmt.bufPrint(&val_buf, "{d}", .{val}) catch "0";