mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
parent
a947f97331
commit
d63298da65
@ -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]);
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user