zig/test/cases/bugs/656.zig
Andrew Kelley c9e01412a4 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
2017-12-14 01:07:23 -05:00

31 lines
697 B
Zig

const assert = @import("std").debug.assert;
const PrefixOp = union(enum) {
Return,
AddrOf: Value,
};
const Value = struct {
align_expr: ?u32,
};
test "nullable if after an if in a switch prong of a switch with 2 prongs in an else" {
foo(false, true);
}
fn foo(a: bool, b: bool) {
var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } };
if (a) {
} else {
switch (prefix_op) {
PrefixOp.AddrOf => |addr_of_info| {
if (b) { }
if (addr_of_info.align_expr) |align_expr| {
assert(align_expr == 1234);
}
},
PrefixOp.Return => {},
}
}
}