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(...@@ -9433,12 +9433,11 @@ pub fn getCoerced(
9433 switch (ip.indexToKey(val)) {9433 switch (ip.indexToKey(val)) {
9434 .undef => return ip.get(gpa, tid, .{ .undef = new_ty }),9434 .undef => return ip.get(gpa, tid, .{ .undef = new_ty }),
9435 .extern_func => |extern_func| if (ip.isFunctionType(new_ty))9435 .extern_func => |extern_func| if (ip.isFunctionType(new_ty))
9436 return ip.get(gpa, tid, .{ .extern_func = .{9436 return ip.getExternFunc(gpa, tid, .{
9437 .ty = new_ty,9437 .ty = new_ty,
9438 .decl = extern_func.decl,9438 .decl = extern_func.decl,
9439 .lib_name = extern_func.lib_name,9439 .lib_name = extern_func.lib_name,
9440 } }),9440 }),
9441
9442 .func => unreachable,9441 .func => unreachable,
94439442
9444 .int => |int| switch (ip.indexToKey(new_ty)) {9443 .int => |int| switch (ip.indexToKey(new_ty)) {
test/behavior/extern.zig+13
...@@ -45,3 +45,16 @@ test "function extern symbol matches extern decl" {...@@ -45,3 +45,16 @@ test "function extern symbol matches extern decl" {
45export fn another_mystery_function() u32 {45export fn another_mystery_function() u32 {
46 return 12345;46 return 12345;
47}47}
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}