| author | |
| committer | |
| log | 7bd9c8238626998f8016086762483114e5c58f70 |
| tree | 544bf96dece1861e7d99062a239e5a01927aedb3 |
| parent | 72fa03badad2e5837f639359a63a75abaa99a479 |
2 files changed, 14 insertions(+), 0 deletions(-)
src/analyze.cpp+7| ... | ... | @@ -2343,6 +2343,13 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa |
| 2343 | 2343 | add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant")); |
| 2344 | 2344 | implicit_type = g->builtin_types.entry_invalid; |
| 2345 | 2345 | } |
| 2346 | if (implicit_type->id != TypeTableEntryIdInvalid && !context->fn_entry) { | |
| 2347 | ConstExprValue *const_val = &get_resolved_expr(variable_declaration->expr)->const_val; | |
| 2348 | if (!const_val->ok) { | |
| 2349 | add_node_error(g, first_executing_node(variable_declaration->expr), | |
| 2350 | buf_sprintf("global variable initializer requires constant expression")); | |
| 2351 | } | |
| 2352 | } | |
| 2346 | 2353 | } |
| 2347 | 2354 | |
| 2348 | 2355 | if (implicit_type == nullptr && is_const) { |
test/run_tests.cpp+7| ... | ... | @@ -1567,6 +1567,13 @@ fn f() => { |
| 1567 | 1567 | }; |
| 1568 | 1568 | } |
| 1569 | 1569 | )SOURCE", 1, ".tmp_source.zig:6:9: error: multiple else prongs in switch expression"); |
| 1570 | ||
| 1571 | add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE( | |
| 1572 | extern { | |
| 1573 | fn foo() i32; | |
| 1574 | } | |
| 1575 | const x = foo(); | |
| 1576 | )SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression"); | |
| 1570 | 1577 | } |
| 1571 | 1578 | |
| 1572 | 1579 | static void print_compiler_invocation(TestCase *test_case) { |