authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2025-03-20 18:50:12-07:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-24 19:04:10+00:00
log89db4f2e9390a75b73be3d20a95df78e376cfdd5
treeb3d321a4f95efaaa808c6c9e676e2f8b0c4328e2
parent972cab5bb027dce3d4f700e381bec3e1724c9504

Sema: use unwrapped generic owner in `getFuncInstanceIes`


2 files changed, 13 insertions(+), 1 deletions(-)

src/InternPool.zig+1-1
......@@ -9455,7 +9455,7 @@ pub fn getFuncInstanceIes(
94559455 try items.ensureUnusedCapacity(4);
94569456
94579457 const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner);
9458 const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(arg.generic_owner).ty).func_type;
9458 const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(generic_owner).ty).func_type;
94599459
94609460 // The strategy here is to add the function decl unconditionally, then to
94619461 // ask if it already exists, and if so, revert the lengths of the mutated
test/behavior/generics.zig+12
......@@ -619,3 +619,15 @@ test "generic parameter resolves to comptime-only type but is not marked comptim
619619 const ct_result = comptime S.foo(u8, false, S.bar);
620620 comptime std.debug.assert(ct_result == 123);
621621}
622
623test "instantiate coerced generic function" {
624 const S = struct {
625 fn generic(comptime T: type, arg: *const u8) !void {
626 _ = T;
627 _ = arg;
628 }
629 };
630 const coerced: fn (comptime type, *u8) anyerror!void = S.generic;
631 var x: u8 = 20;
632 try coerced(u8, &x);
633}