Skip to content

Commit

Permalink
fix crash with error peer type resolution
Browse files Browse the repository at this point in the history
closes #765
  • Loading branch information
andrewrk committed Feb 9, 2018
1 parent 2c697e5 commit 3919afc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ir.cpp
Expand Up @@ -7279,7 +7279,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
prev_inst = cur_inst;
}

TypeTableEntry *prev_err_set_type = prev_type->data.error_union.err_set_type;
TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;

if (!resolve_inferred_error_set(ira, prev_err_set_type, cur_inst->source_node)) {
Expand Down
25 changes: 25 additions & 0 deletions test/cases/error.zig
Expand Up @@ -150,3 +150,28 @@ fn testErrToIntWithOnePossibleValue(x: error{A}, comptime value: u32) void {
@compileError("bad");
}
}

test "error union peer type resolution" {
testErrorUnionPeerTypeResolution(1);
comptime testErrorUnionPeerTypeResolution(1);
}

fn testErrorUnionPeerTypeResolution(x: i32) void {
const y = switch (x) {
1 => bar_1(),
2 => baz_1(),
else => quux_1(),
};
}

fn bar_1() error {
return error.A;
}

fn baz_1() !i32 {
return error.B;
}

fn quux_1() !i32 {
return error.C;
}

0 comments on commit 3919afc

Please sign in to comment.