ip: use getExternFunc in getCoerced

`ip.get` specifically doesn't allow `extern_func` keys to access it.
This commit is contained in:
David Rubin 2024-07-16 18:46:31 -07:00 committed by Andrew Kelley
parent 9232425b8f
commit 7591df5172
2 changed files with 15 additions and 3 deletions

View File

@ -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)) {

View File

@ -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);
}