Commit d63298da65
Changed files (2)
test
behavior
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]);
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);
+}