zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 720d82721fa6013b2e7e7ff2866db9404bfd2901 (tree)
parent 92dfc07489c3f8514792434e2857b419ebf1f208
Author: Veikka Tuominen <git@vexu.eu>
Date:   Sun, 22 Jan 2023 17:26:32 +0200

Sema: ensure args to inline comptime args are comptime-known

Closes #14413

Diffstat:
Msrc/Sema.zig | 5+++++
Atest/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig | 17+++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -6879,6 +6879,8 @@ fn analyzeInlineCallArg( if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err); return err; }; + } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) { + _ = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime"); } const casted_arg = sema.coerceExtra(arg_block, param_ty, uncasted_arg, arg_src, .{ .param_src = .{ .func_inst = func_inst, @@ -6952,6 +6954,9 @@ fn analyzeInlineCallArg( .val = arg_val, }; } else { + if (zir_tags[inst] == .param_anytype_comptime) { + _ = try sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime"); + } sema.inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); } diff --git a/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig b/test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig @@ -0,0 +1,17 @@ +inline fn needComptime(comptime a: u64) void { + if (a != 0) @compileError("foo"); +} +fn acceptRuntime(value: u64) void { + needComptime(value); +} +pub export fn entry() void { + var value: u64 = 0; + acceptRuntime(value); +} + +// error +// backend=stage2 +// target=native +// +// :5:18: error: unable to resolve comptime value +// :5:18: note: parameter is comptime