Sema: fix function type callconv inference

This commit is contained in:
Veikka Tuominen 2022-06-03 23:49:16 +03:00
parent 6d44c0a16c
commit 50a6b0f3ac
2 changed files with 11 additions and 7 deletions

View File

@ -6654,7 +6654,11 @@ fn zirFunc(
src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;
}
const cc: std.builtin.CallingConvention = if (sema.owner_decl.is_exported)
// If this instruction has a body it means it's the type of the `owner_decl`
// otherwise it's a function type without a `callconv` attribute and should
// never be `.C`.
// NOTE: revisit when doing #1717
const cc: std.builtin.CallingConvention = if (sema.owner_decl.is_exported and has_body)
.C
else
.Unspecified;

View File

@ -23,9 +23,9 @@ pub export fn entry3() void {
// error
// backend=stage2,llvm
//
// :6:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known
// :6:33: note: use '*const fn() callconv(.C) void' for a function pointer type
// :13:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known
// :13:33: note: use '*const fn() callconv(.C) void' for a function pointer type
// :19:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known
// :19:33: note: use '*const fn() callconv(.C) void' for a function pointer type
// :6:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
// :6:5: note: use '*const fn() void' for a function pointer type
// :13:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
// :13:5: note: use '*const fn() void' for a function pointer type
// :19:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
// :19:5: note: use '*const fn() void' for a function pointer type