Commit b508441859
Changed files (2)
src
test
src/codegen.cpp
@@ -916,11 +916,12 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
TypeTableEntry *child_type = expr_type->data.error.child_type;
// TODO in debug mode, put a panic here if the error is not 0
if (child_type->size_in_bits > 0) {
+ add_debug_source_node(g, node);
LLVMValueRef child_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 1, "");
if (handle_is_ptr(child_type)) {
return child_val_ptr;
} else {
- return expr_val;
+ return LLVMBuildLoad(g->builder, child_val_ptr, "");
}
} else {
return nullptr;
test/run_tests.cpp
@@ -1329,6 +1329,21 @@ fn f() -> &void {
pub fn main(args: [][]u8) -> %void {
const a = f();
return *a;
+}
+ )SOURCE", "OK\n");
+
+ add_simple_case("unwrap simple value from error", R"SOURCE(
+import "std.zig";
+fn do() -> %isize {
+ 13
+}
+
+pub fn main(args: [][]u8) -> %void {
+ const i = %%do();
+ if (i != 13) {
+ %%stdout.printf("BAD\n");
+ }
+ %%stdout.printf("OK\n");
}
)SOURCE", "OK\n");
}