Files
sx/examples/1137-diagnostics-value-param-type-fn-no-cascade.sx
agra a7dcb23b70 fix(ir): poison type-fn binder on failed value-param bind (0083)
A failed value-param bind on a type-returning function (e.g.
`MakeC :: ($K: Count, $T: Type) -> Type { return [K]T; }` with
`a : MakeC(5_000_000_000, s64)`) emitted its correct range diagnostic
but then `instantiateTypeFunction` returned `null`, so
`resolveParameterizedWithBindings` fell through to an empty-struct
placeholder named after the function. The binding `a` got that
placeholder type, so a later `a.len` cascaded a bogus second error
`field 'len' not found on type 'MakeC'`.

The struct binder (`instantiateGenericStruct`) already returns
`.unresolved` here; the type-fn binder now matches it — a 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 an aliased
constraint, a non-const arg, and an unknown type arg.

Regression: examples/1137-diagnostics-value-param-type-fn-no-cascade.sx
2026-06-04 14:38:18 +03:00

28 lines
1.3 KiB
Plaintext

// 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 '<fn>'` 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);
}