diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 19:09:54 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 19:09:54 -0700 |
| commit | 61a53a587558ff1fe1b0ec98bb424022885edccf (patch) | |
| tree | 0e0ad82f7998a473104ec6fa07cb051a1b56a7c3 /test | |
| parent | ac52e005640e9dc7829356f857a82b0bc3894245 (diff) | |
| download | zig-61a53a587558ff1fe1b0ec98bb424022885edccf.tar.gz zig-61a53a587558ff1fe1b0ec98bb424022885edccf.zip | |
AstGen: fix if, orelse, catch, with unreachable bodies
Before, the system to replace a result location pointer with a
traditional break instruction did not notice the case when one of the
bodies was unreachable. Now, the emitted ZIR code is improved and
simplified in this case, resulting in a new passing behavior test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/if.zig | 8 | ||||
| -rw-r--r-- | test/behavior/if_stage1.zig | 11 |
2 files changed, 8 insertions, 11 deletions
diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 191d4817df..a1f722d827 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -65,3 +65,11 @@ test "labeled break inside comptime if inside runtime if" { } try expect(answer == 42); } + +test "const result loc, runtime if cond, else unreachable" { + const Num = enum { One, Two }; + + var t = true; + const x = if (t) Num.Two else unreachable; + try expect(x == .Two); +} diff --git a/test/behavior/if_stage1.zig b/test/behavior/if_stage1.zig index 36500fbaee..8b299deaec 100644 --- a/test/behavior/if_stage1.zig +++ b/test/behavior/if_stage1.zig @@ -2,17 +2,6 @@ const std = @import("std"); const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -test "const result loc, runtime if cond, else unreachable" { - const Num = enum { - One, - Two, - }; - - var t = true; - const x = if (t) Num.Two else unreachable; - try expect(x == .Two); -} - test "if prongs cast to expected type instead of peer type resolution" { const S = struct { fn doTheTest(f: bool) !void { |
