authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-07-16 18:46:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 01:00:49-07:00
log7591df5172e9f8e80130b619b7eaa60846d3e851
tree594c4abce2d54638c4d2c8b402d3ed3e520bfb81
parent9232425b8f68e84d192c9c77ca0c3b7b2547d195

ip: use `getExternFunc` in `getCoerced`

`ip.get` specifically doesn't allow `extern_func` keys to access it.

2 files changed, 15 insertions(+), 3 deletions(-)

src/InternPool.zig+2-3
......@@ -9433,12 +9433,11 @@ pub fn getCoerced(
94339433 switch (ip.indexToKey(val)) {
94349434 .undef => return ip.get(gpa, tid, .{ .undef = new_ty }),
94359435 .extern_func => |extern_func| if (ip.isFunctionType(new_ty))
9436 return ip.get(gpa, tid, .{ .extern_func = .{
9436 return ip.getExternFunc(gpa, tid, .{
94379437 .ty = new_ty,
94389438 .decl = extern_func.decl,
94399439 .lib_name = extern_func.lib_name,
9440 } }),
9441
9440 }),
94429441 .func => unreachable,
94439442
94449443 .int => |int| switch (ip.indexToKey(new_ty)) {
test/behavior/extern.zig+13
......@@ -45,3 +45,16 @@ test "function extern symbol matches extern decl" {
4545export fn another_mystery_function() u32 {
4646 return 12345;
4747}
48
49extern fn c_extern_function() [*c]u32;
50
51test "coerce extern function types" {
52 const S = struct {
53 export fn c_extern_function() [*c]u32 {
54 return null;
55 }
56 };
57 _ = S;
58
59 _ = @as(fn () callconv(.C) ?*u32, c_extern_function);
60}