InternPool: handle funcZirBodyInst for func_coerced

Closes #18039
This commit is contained in:
Veikka Tuominen 2023-11-21 13:44:03 +02:00
parent a947f97331
commit d63298da65
2 changed files with 28 additions and 0 deletions

View File

@ -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); assert(ip.items.items(.tag)[func_decl_index] == .func_decl);
break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index; 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, else => unreachable,
}; };
return @enumFromInt(ip.extra.items[extra_index]); return @enumFromInt(ip.extra.items[extra_index]);

View File

@ -499,3 +499,24 @@ test "call inline fn through pointer" {
const f = &S.foo; const f = &S.foo;
try f(123); 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);
}