Skip to content

Commit d63298d

Browse files
committed
InternPool: handle funcZirBodyInst for func_coerced
Closes #18039
1 parent a947f97 commit d63298d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/InternPool.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8301,6 +8301,13 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index {
83018301
assert(ip.items.items(.tag)[func_decl_index] == .func_decl);
83028302
break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index;
83038303
},
8304+
.func_coerced => {
8305+
const datas = ip.items.items(.data);
8306+
const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[
8307+
datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").?
8308+
]);
8309+
return ip.funcZirBodyInst(uncoerced_func_index);
8310+
},
83048311
else => unreachable,
83058312
};
83068313
return @enumFromInt(ip.extra.items[extra_index]);

test/behavior/call.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,24 @@ test "call inline fn through pointer" {
499499
const f = &S.foo;
500500
try f(123);
501501
}
502+
503+
test "call coerced function" {
504+
const T = struct {
505+
x: f64,
506+
const T = @This();
507+
usingnamespace Implement(1);
508+
const F = fn (comptime f64) type;
509+
const Implement: F = opaque {
510+
fn implementer(comptime val: anytype) type {
511+
return opaque {
512+
fn incr(self: T) T {
513+
return .{ .x = self.x + val };
514+
}
515+
};
516+
}
517+
}.implementer;
518+
};
519+
520+
const a = T{ .x = 3 };
521+
try std.testing.expect(a.incr().x == 4);
522+
}

0 commit comments

Comments
 (0)