Skip to content

Commit c9e0141

Browse files
committedDec 14, 2017
fix compiler crash in a nullable if after an if in...
...a switch prong of a switch with 2 prongs in an else closes #656
·
0.15.10.2.0
1 parent f55fdc0 commit c9e0141

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed
 

‎src/ir.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
11911191
if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
11921192
ir_ref_instruction(init_value, irb->current_basic_block);
11931193

1194+
var->decl_instruction = &decl_var_instruction->base;
1195+
11941196
return &decl_var_instruction->base;
11951197
}
11961198

@@ -5108,9 +5110,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
51085110
if (init_value == irb->codegen->invalid_instruction)
51095111
return init_value;
51105112

5111-
IrInstruction *result = ir_build_var_decl(irb, scope, node, var, type_instruction, align_value, init_value);
5112-
var->decl_instruction = result;
5113-
return result;
5113+
return ir_build_var_decl(irb, scope, node, var, type_instruction, align_value, init_value);
51145114
}
51155115

51165116
static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {

‎test/behavior.zig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ comptime {
88
_ = @import("cases/bool.zig");
99
_ = @import("cases/bugs/394.zig");
1010
_ = @import("cases/bugs/655.zig");
11+
_ = @import("cases/bugs/656.zig");
1112
_ = @import("cases/cast.zig");
1213
_ = @import("cases/const_slice_child.zig");
1314
_ = @import("cases/defer.zig");

‎test/cases/bugs/656.zig‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const assert = @import("std").debug.assert;
2+
3+
const PrefixOp = union(enum) {
4+
Return,
5+
AddrOf: Value,
6+
};
7+
8+
const Value = struct {
9+
align_expr: ?u32,
10+
};
11+
12+
test "nullable if after an if in a switch prong of a switch with 2 prongs in an else" {
13+
foo(false, true);
14+
}
15+
16+
fn foo(a: bool, b: bool) {
17+
var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } };
18+
if (a) {
19+
} else {
20+
switch (prefix_op) {
21+
PrefixOp.AddrOf => |addr_of_info| {
22+
if (b) { }
23+
if (addr_of_info.align_expr) |align_expr| {
24+
assert(align_expr == 1234);
25+
}
26+
},
27+
PrefixOp.Return => {},
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.