commit d63298da65df7fa2712bf9e9d65d36cd91af22fa (tree)
parent a947f97331595df4ee340bbcfcef7241555c687b
Author: Veikka Tuominen <git@vexu.eu>
Date: Tue, 21 Nov 2023 13:44:03 +0200
InternPool: handle `funcZirBodyInst` for `func_coerced`
Closes #18039
Diffstat:
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/src/InternPool.zig b/src/InternPool.zig
@@ -8301,6 +8301,13 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index {
assert(ip.items.items(.tag)[func_decl_index] == .func_decl);
break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index;
},
+ .func_coerced => {
+ const datas = ip.items.items(.data);
+ const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[
+ datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").?
+ ]);
+ return ip.funcZirBodyInst(uncoerced_func_index);
+ },
else => unreachable,
};
return @enumFromInt(ip.extra.items[extra_index]);
diff --git a/test/behavior/call.zig b/test/behavior/call.zig
@@ -499,3 +499,24 @@ test "call inline fn through pointer" {
const f = &S.foo;
try f(123);
}
+
+test "call coerced function" {
+ const T = struct {
+ x: f64,
+ const T = @This();
+ usingnamespace Implement(1);
+ const F = fn (comptime f64) type;
+ const Implement: F = opaque {
+ fn implementer(comptime val: anytype) type {
+ return opaque {
+ fn incr(self: T) T {
+ return .{ .x = self.x + val };
+ }
+ };
+ }
+ }.implementer;
+ };
+
+ const a = T{ .x = 3 };
+ try std.testing.expect(a.incr().x == 4);
+}