From badbf0415d4e382262c1a6a84646596bd3bdece7 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 3 Oct 2022 14:33:37 +0300 Subject: [PATCH] Sema: fix comptime only types being allowed on extern functions Closes #13022 --- src/Sema.zig | 4 ++-- ...omptime_only_params_not_allowed_on_extern_fns.zig | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/cases/compile_errors/comptime_only_params_not_allowed_on_extern_fns.zig diff --git a/src/Sema.zig b/src/Sema.zig index eb228c824ede..7dea22099520 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7970,7 +7970,7 @@ fn funcCommon( i, &is_generic, cc_workaround, - has_body, + has_body or is_extern, ) catch |err| switch (err) { error.NeededSourceLocation => { const decl = sema.mod.declPtr(block.src_decl); @@ -7982,7 +7982,7 @@ fn funcCommon( i, &is_generic, cc_workaround, - has_body, + has_body or is_extern, ); return error.AnalysisFail; }, diff --git a/test/cases/compile_errors/comptime_only_params_not_allowed_on_extern_fns.zig b/test/cases/compile_errors/comptime_only_params_not_allowed_on_extern_fns.zig new file mode 100644 index 000000000000..bb67e0726ad4 --- /dev/null +++ b/test/cases/compile_errors/comptime_only_params_not_allowed_on_extern_fns.zig @@ -0,0 +1,12 @@ +pub extern fn signal(handler: fn (c_int, c_int) callconv(.C) void) void; +fn interruptFn(_: c_int, _: c_int) callconv(.C) void {} + +pub export fn entry() void { + _ = signal(interruptFn); +} + +// error +// backend=stage2 +// target=native +// +// :1:22: error: parameter of type 'fn(c_int, c_int) callconv(.C) void' must be declared comptime