commit 76d0e49e612d661b57b795cd81f5ba06dc26ceca (tree)
parent e4bc8d22c2f518353d31d8c99de8d35e5ead0c67
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Sun, 8 Jan 2017 10:54:05 -0500
fix unable to eval const expr test case
Diffstat:
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -5266,7 +5266,9 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) {
if (instruction->id == IrInstructionIdReturn) {
IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
IrInstruction *value = ret_inst->value;
- assert(value->value.special != ConstValSpecialRuntime);
+ if (value->value.special == ConstValSpecialRuntime) {
+ return nullptr;
+ }
return value;
} else if (ir_has_side_effects(instruction)) {
return nullptr;
diff --git a/test/run_tests.cpp b/test/run_tests.cpp
@@ -1128,7 +1128,7 @@ const Foo = struct {
};
var global_var: usize = 1;
fn get() -> usize { global_var }
- )SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");
+ )SOURCE", 1, ".tmp_source.zig:3:12: error: unable to evaluate constant expression");
add_compile_fail_case("unnecessary if statement", R"SOURCE(