zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 89db4f2e9390a75b73be3d20a95df78e376cfdd5 (tree)
parent 972cab5bb027dce3d4f700e381bec3e1724c9504
Author: David Rubin <daviru007@icloud.com>
Date:   Thu, 20 Mar 2025 18:50:12 -0700

Sema: use unwrapped generic owner in `getFuncInstanceIes`

Diffstat:
Msrc/InternPool.zig | 2+-
Mtest/behavior/generics.zig | 12++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/InternPool.zig b/src/InternPool.zig @@ -9455,7 +9455,7 @@ pub fn getFuncInstanceIes( try items.ensureUnusedCapacity(4); const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner); - const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(arg.generic_owner).ty).func_type; + const generic_owner_ty = ip.indexToKey(ip.funcDeclInfo(generic_owner).ty).func_type; // The strategy here is to add the function decl unconditionally, then to // ask if it already exists, and if so, revert the lengths of the mutated diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig @@ -619,3 +619,15 @@ test "generic parameter resolves to comptime-only type but is not marked comptim const ct_result = comptime S.foo(u8, false, S.bar); comptime std.debug.assert(ct_result == 123); } + +test "instantiate coerced generic function" { + const S = struct { + fn generic(comptime T: type, arg: *const u8) !void { + _ = T; + _ = arg; + } + }; + const coerced: fn (comptime type, *u8) anyerror!void = S.generic; + var x: u8 = 20; + try coerced(u8, &x); +}