diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-28 18:28:08 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-28 18:28:08 -0700 |
| commit | 4dd65316b7d5756809394710078718b3ee536a9b (patch) | |
| tree | e058370c2dc1a01693134a15a5fd8ca6cb7b550d /test/behavior/basic.zig | |
| parent | 857743473ced48a493a713c0b86340ee110ce909 (diff) | |
| download | zig-4dd65316b7d5756809394710078718b3ee536a9b.tar.gz zig-4dd65316b7d5756809394710078718b3ee536a9b.zip | |
AstGen: coerce break operands of labeled blocks
Similar code was already in place for conditional branches. This updates
AstGen to do the same for labeled blocks. It takes advantage of the
`store_to_block_ptr` instructions by mutating them in place to become
`as` instructions, coercing the break operands before they are returned
from the block.
Diffstat (limited to 'test/behavior/basic.zig')
| -rw-r--r-- | test/behavior/basic.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 6c21b8dd6c..134ca1a235 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -875,3 +875,15 @@ test "catch in block has correct result location" { }; try expect(config_h_text == 1); } + +test "labeled block with runtime branch forwards its result location type to break statements" { + const E = enum { a, b }; + var a = false; + const e: E = blk: { + if (a) { + break :blk .a; + } + break :blk .b; + }; + try expect(e == .b); +} |
