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
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user