| author | |
| committer | |
| log | 36cf9f0c721a9b1be04490d06dffae9e070fd724 |
| tree | bd6d6e7700e6baf38fe53a5b41f1ab5086fc1eb6 |
| parent | 26ea20d88fb1b201546e29058ac4aa5d4760a577 |
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, |
| 3281 | 3281 | return resolve_expr_const_val_as_type(g, node, |
| 3282 | 3282 | get_array_type(g, child_type, const_val->data.x_bignum.data.x_uint)); |
| 3283 | 3283 | } |
| 3284 | } else { | |
| 3284 | } else if (context->fn_entry) { | |
| 3285 | 3285 | return resolve_expr_const_val_as_type(g, node, |
| 3286 | 3286 | 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; | |
| 3287 | 3291 | } |
| 3288 | 3292 | } else { |
| 3289 | 3293 | return resolve_expr_const_val_as_type(g, node, |
test/run_tests.cpp+7| ... | ... | @@ -2027,6 +2027,13 @@ fn a(x: i32) { |
| 2027 | 2027 | const y = @const_eval(x); |
| 2028 | 2028 | } |
| 2029 | 2029 | )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( | |
| 2032 | struct Foo { | |
| 2033 | y: [get()]u8, | |
| 2034 | } | |
| 2035 | fn get() -> isize { 1 } | |
| 2036 | )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression"); | |
| 2030 | 2037 | } |
| 2031 | 2038 | |
| 2032 | 2039 | ////////////////////////////////////////////////////////////////////////////// |