authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 15:16:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 15:16:36-07:00
log36cf9f0c721a9b1be04490d06dffae9e070fd724
treebd6d6e7700e6baf38fe53a5b41f1ab5086fc1eb6
parent26ea20d88fb1b201546e29058ac4aa5d4760a577

error for non const expr in array size outside fn


2 files changed, 12 insertions(+), 1 deletions(-)

src/analyze.cpp+5-1
......@@ -3281,9 +3281,13 @@ static TypeTableEntry *analyze_array_type(CodeGen *g, ImportTableEntry *import,
32813281 return resolve_expr_const_val_as_type(g, node,
32823282 get_array_type(g, child_type, const_val->data.x_bignum.data.x_uint));
32833283 }
3284 } else {
3284 } else if (context->fn_entry) {
32853285 return resolve_expr_const_val_as_type(g, node,
32863286 get_slice_type(g, child_type, node->data.array_type.is_const));
3287 } else {
3288 add_node_error(g, first_executing_node(size_node),
3289 buf_sprintf("unable to evaluate constant expression"));
3290 return g->builtin_types.entry_invalid;
32873291 }
32883292 } else {
32893293 return resolve_expr_const_val_as_type(g, node,
test/run_tests.cpp+7
......@@ -2027,6 +2027,13 @@ fn a(x: i32) {
20272027 const y = @const_eval(x);
20282028}
20292029 )SOURCE", 1, ".tmp_source.zig:3:27: error: unable to evaluate constant expression");
2030
2031 add_compile_fail_case("non constant expression in array size outside function", R"SOURCE(
2032struct Foo {
2033 y: [get()]u8,
2034}
2035fn get() -> isize { 1 }
2036 )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");
20302037}
20312038
20322039//////////////////////////////////////////////////////////////////////////////