fix(0126): array args bind []$T generic params; uninferrable type params diagnose at the call
extractTypeParam's slice arm only extracted from slice-typed args, so first(a) with a : [3]s64 at first :: (xs: []$T) -> T left T unbound and the mono body reached LLVM emission carrying the .unresolved sentinel (panic). The arm now also extracts from array args via the array's element type — mirroring the array→slice promotion concrete slice params already perform; the existing arg coercion handles the rest. lowerGenericCall additionally diagnoses any still-uninferrable TYPE param at the call site instead of monomorphizing unbound — the deliberate string-at-[]$T gap used to hit the same sentinel panic and now errors with a source-located message. Comptime value params ($N: u32) and ..$Ts packs bind through their own dispatch and stay exempt. Regressions: examples/0212-generics-array-arg-slice-param.sx (scalar / u8 / struct elements + the slice spelling) and examples/1168-diagnostics-generic-param-uninferrable.sx (string arg diagnostic) — both failed pre-fix.
This commit is contained in:
@@ -1323,6 +1323,25 @@ pub fn lowerGenericCall(self: *Lowering, fd: *const ast.FnDecl, base_name: []con
|
||||
var bindings = self.genericResolver().buildTypeBindings(fd, call_node.args);
|
||||
defer bindings.deinit();
|
||||
|
||||
// An uninferrable TYPE param must diagnose here: monomorphizing with
|
||||
// it unbound stamps `.unresolved` through the body and trips the
|
||||
// emitter's sentinel panic instead of surfacing a source error.
|
||||
// Comptime VALUE params (`$N: u32`) and `..$Ts` packs bind through
|
||||
// their own dispatch and are exempt.
|
||||
for (fd.type_params) |tp| {
|
||||
if (tp.is_variadic) continue;
|
||||
if (tp.constraint.data != .type_expr) continue;
|
||||
const cname = tp.constraint.data.type_expr.name;
|
||||
const is_type_param = std.mem.eql(u8, cname, "Type") or
|
||||
self.program_index.protocol_decl_map.contains(cname) or
|
||||
self.program_index.protocol_ast_map.contains(cname);
|
||||
if (is_type_param and !bindings.contains(tp.name)) {
|
||||
if (self.diagnostics) |d|
|
||||
d.addFmt(.err, call_node.callee.span, "cannot infer generic type parameter '{s}' for '{s}' from this call's arguments", .{ tp.name, base_name });
|
||||
return Ref.none;
|
||||
}
|
||||
}
|
||||
|
||||
const types_passed_explicitly = call_node.args.len == fd.params.len;
|
||||
const mangled_name = self.genericResolver().mangleGenericName(base_name, fd, &bindings);
|
||||
|
||||
|
||||
@@ -554,11 +554,15 @@ pub fn extractTypeParam(self: *Lowering, type_node: *const Node, arg_ty: TypeId,
|
||||
.type_expr => |te| if (std.mem.eql(u8, te.name, tp_name)) arg_ty else null,
|
||||
.identifier => |id| if (std.mem.eql(u8, id.name, tp_name)) arg_ty else null,
|
||||
.slice_type_expr => |st| blk: {
|
||||
// arg_ty should be a slice → extract element type
|
||||
// arg_ty should be a slice → extract element type. An array
|
||||
// arg coerces to a slice at a `[]T` param (the same promotion
|
||||
// concrete slice params perform), so it binds from its
|
||||
// element type too (issue 0126).
|
||||
if (arg_ty.isBuiltin()) break :blk null;
|
||||
const info = self.module.types.get(arg_ty);
|
||||
break :blk switch (info) {
|
||||
.slice => |s| self.extractTypeParam(st.element_type, s.element, tp_name),
|
||||
.array => |a| self.extractTypeParam(st.element_type, a.element, tp_name),
|
||||
else => null,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user