| author | |
| committer | |
| log | d63298da65df7fa2712bf9e9d65d36cd91af22fa |
| tree | a6da55d3509c34bc9de0199e2bdf408e5ab27ac6 |
| parent | a947f97331595df4ee340bbcfcef7241555c687b |
Closes #180392 files changed, 28 insertions(+), 0 deletions(-)
src/InternPool.zig+7| ... | @@ -8301,6 +8301,13 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { | ... | @@ -8301,6 +8301,13 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { |
| 8301 | assert(ip.items.items(.tag)[func_decl_index] == .func_decl); | 8301 | assert(ip.items.items(.tag)[func_decl_index] == .func_decl); |
| 8302 | break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index; | 8302 | break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index; |
| 8303 | }, | 8303 | }, |
| 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 | }, | ||
| 8304 | else => unreachable, | 8311 | else => unreachable, |
| 8305 | }; | 8312 | }; |
| 8306 | return @enumFromInt(ip.extra.items[extra_index]); | 8313 | return @enumFromInt(ip.extra.items[extra_index]); |
test/behavior/call.zig+21| ... | @@ -499,3 +499,24 @@ test "call inline fn through pointer" { | ... | @@ -499,3 +499,24 @@ test "call inline fn through pointer" { |
| 499 | const f = &S.foo; | 499 | const f = &S.foo; |
| 500 | try f(123); | 500 | try f(123); |
| 501 | } | 501 | } |
| 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 | } |