Sema: avoid panic on callconv(.C) generic return type

Fixes #14854
This commit is contained in:
Ian Johnson 2023-03-12 13:08:15 -04:00 committed by Veikka Tuominen
parent 1d96a17af4
commit adc6dec26b
3 changed files with 15 additions and 1 deletions

View File

@ -8782,7 +8782,7 @@ fn funcCommon(
};
return sema.failWithOwnedErrorMsg(msg);
}
if (!Type.fnCallingConventionAllowsZigTypes(cc_resolved) and !try sema.validateExternType(return_type, .ret_ty)) {
if (!ret_poison and !Type.fnCallingConventionAllowsZigTypes(cc_resolved) and !try sema.validateExternType(return_type, .ret_ty)) {
const msg = msg: {
const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
return_type.fmt(sema.mod), @tagName(cc_resolved),

View File

@ -141,6 +141,7 @@ test {
_ = @import("behavior/bugs/13664.zig");
_ = @import("behavior/bugs/13714.zig");
_ = @import("behavior/bugs/13785.zig");
_ = @import("behavior/bugs/14854.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,13 @@
const testing = @import("std").testing;
test {
try testing.expect(getGeneric(u8, getU8) == 123);
}
fn getU8() callconv(.C) u8 {
return 123;
}
fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T {
return supplier();
}