mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Change error when runtime value passed to comptime arg
This commit is contained in:
parent
129ccad434
commit
a39d3155b4
2 changed files with 13 additions and 8 deletions
|
|
@ -20068,6 +20068,11 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
|
||||||
|
|
||||||
ZigValue *arg_val;
|
ZigValue *arg_val;
|
||||||
|
|
||||||
|
if (comptime_arg && !instr_is_comptime(casted_arg)) {
|
||||||
|
ir_add_error(ira, &casted_arg->base,
|
||||||
|
buf_sprintf("runtime value cannot be passed to comptime arg"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (comptime_arg) {
|
if (comptime_arg) {
|
||||||
arg_part_of_generic_id = true;
|
arg_part_of_generic_id = true;
|
||||||
arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
|
arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
|
||||||
|
|
|
||||||
|
|
@ -5314,7 +5314,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||||
\\
|
\\
|
||||||
\\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
|
\\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
|
||||||
, &[_][]const u8{
|
, &[_][]const u8{
|
||||||
"tmp.zig:3:16: error: unable to evaluate constant expression",
|
"tmp.zig:3:16: error: runtime value cannot be passed to comptime arg",
|
||||||
});
|
});
|
||||||
|
|
||||||
cases.add("assign null to non-optional pointer",
|
cases.add("assign null to non-optional pointer",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue