Change error when runtime value passed to comptime arg

This commit is contained in:
frmdstryr 2020-10-16 13:16:09 -04:00 committed by Veikka Tuominen
parent 129ccad434
commit a39d3155b4
2 changed files with 13 additions and 8 deletions

View file

@ -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);

View file

@ -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",