From 7591df5172e9f8e80130b619b7eaa60846d3e851 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Tue, 16 Jul 2024 18:46:31 -0700 Subject: [PATCH] ip: use `getExternFunc` in `getCoerced` `ip.get` specifically doesn't allow `extern_func` keys to access it. --- src/InternPool.zig | 5 ++--- test/behavior/extern.zig | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/InternPool.zig b/src/InternPool.zig index 12492e0502..c3cee5852b 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -9433,12 +9433,11 @@ pub fn getCoerced( switch (ip.indexToKey(val)) { .undef => return ip.get(gpa, tid, .{ .undef = new_ty }), .extern_func => |extern_func| if (ip.isFunctionType(new_ty)) - return ip.get(gpa, tid, .{ .extern_func = .{ + return ip.getExternFunc(gpa, tid, .{ .ty = new_ty, .decl = extern_func.decl, .lib_name = extern_func.lib_name, - } }), - + }), .func => unreachable, .int => |int| switch (ip.indexToKey(new_ty)) { diff --git a/test/behavior/extern.zig b/test/behavior/extern.zig index 9469b4dc21..cd80c545ce 100644 --- a/test/behavior/extern.zig +++ b/test/behavior/extern.zig @@ -45,3 +45,16 @@ test "function extern symbol matches extern decl" { export fn another_mystery_function() u32 { return 12345; } + +extern fn c_extern_function() [*c]u32; + +test "coerce extern function types" { + const S = struct { + export fn c_extern_function() [*c]u32 { + return null; + } + }; + _ = S; + + _ = @as(fn () callconv(.C) ?*u32, c_extern_function); +}