mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 12:33:19 +00:00
error for non const expr in array size outside fn
This commit is contained in:
parent
26ea20d88f
commit
36cf9f0c72
@ -3281,9 +3281,13 @@ static TypeTableEntry *analyze_array_type(CodeGen *g, ImportTableEntry *import,
|
||||
return resolve_expr_const_val_as_type(g, node,
|
||||
get_array_type(g, child_type, const_val->data.x_bignum.data.x_uint));
|
||||
}
|
||||
} else {
|
||||
} else if (context->fn_entry) {
|
||||
return resolve_expr_const_val_as_type(g, node,
|
||||
get_slice_type(g, child_type, node->data.array_type.is_const));
|
||||
} else {
|
||||
add_node_error(g, first_executing_node(size_node),
|
||||
buf_sprintf("unable to evaluate constant expression"));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
} else {
|
||||
return resolve_expr_const_val_as_type(g, node,
|
||||
|
||||
@ -2027,6 +2027,13 @@ fn a(x: i32) {
|
||||
const y = @const_eval(x);
|
||||
}
|
||||
)SOURCE", 1, ".tmp_source.zig:3:27: error: unable to evaluate constant expression");
|
||||
|
||||
add_compile_fail_case("non constant expression in array size outside function", R"SOURCE(
|
||||
struct Foo {
|
||||
y: [get()]u8,
|
||||
}
|
||||
fn get() -> isize { 1 }
|
||||
)SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user