fix %% prefix operator codegen for simple values

closes #93
This commit is contained in:
Andrew Kelley 2016-01-27 14:49:48 -07:00
parent 0a26586724
commit b508441859
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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");
}