authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-03 23:49:16+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-04 11:33:18+03:00
log50a6b0f3acb2a17f74d57301dbf3d4b13e30953b
treee53320c89cff35f60a1e11e57a0c938f0b793021
parent6d44c0a16c90a13cb3507751e2015edf51c642cf

Sema: fix function type callconv inference


2 files changed, 11 insertions(+), 7 deletions(-)

src/Sema.zig+5-1
...@@ -6654,7 +6654,11 @@ fn zirFunc(...@@ -6654,7 +6654,11 @@ fn zirFunc(
6654 src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;6654 src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data;
6655 }6655 }
66566656
6657 const cc: std.builtin.CallingConvention = if (sema.owner_decl.is_exported)6657 // If this instruction has a body it means it's the type of the `owner_decl`
6658 // otherwise it's a function type without a `callconv` attribute and should
6659 // never be `.C`.
6660 // NOTE: revisit when doing #1717
6661 const cc: std.builtin.CallingConvention = if (sema.owner_decl.is_exported and has_body)
6658 .C6662 .C
6659 else6663 else
6660 .Unspecified;6664 .Unspecified;
test/cases/compile_errors/runtime_indexing_comptime_array.zig+6-6
...@@ -23,9 +23,9 @@ pub export fn entry3() void {...@@ -23,9 +23,9 @@ pub export fn entry3() void {
23// error23// error
24// backend=stage2,llvm24// backend=stage2,llvm
25//25//
26// :6:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known26// :6:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
27// :6:33: note: use '*const fn() callconv(.C) void' for a function pointer type27// :6:5: note: use '*const fn() void' for a function pointer type
28// :13:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known28// :13:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
29// :13:33: note: use '*const fn() callconv(.C) void' for a function pointer type29// :13:5: note: use '*const fn() void' for a function pointer type
30// :19:33: error: values of type '[2]fn() callconv(.C) void' must be comptime known, but index value is runtime known30// :19:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known
31// :19:33: note: use '*const fn() callconv(.C) void' for a function pointer type31// :19:5: note: use '*const fn() void' for a function pointer type