diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2022-02-06 22:11:41 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-06 21:26:26 -0500 |
| commit | fd1284ebd07ded1c67bbaff4c14f093051e56f59 (patch) | |
| tree | 3ceb66a3288aae5aa8495ff00e7af89c9561f134 /test | |
| parent | adc9a282d8b3cbe58e07c965fe40fb1dd8666bd7 (diff) | |
| download | zig-fd1284ebd07ded1c67bbaff4c14f093051e56f59.tar.gz zig-fd1284ebd07ded1c67bbaff4c14f093051e56f59.zip | |
stage2: apply type coercion in if expressions
When setting the break value in an if expression we must explicitly
check if a result location type coercion that needs to happen. This was
already done for switch expression, so let's just imitate that check
and fix for if expressions. To make this possible, we now also propagate
`rl_ty_inst` to sub scopes.
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/basic.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 186418b69c..0c2cfbc3d5 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -693,3 +693,9 @@ test "variable name containing underscores does not shadow int primitive" { _ = u6__4; _ = i2_04_8; } + +test "if expression type coercion" { + var cond: bool = true; + const x: u16 = if (cond) 1 else 0; + try expect(@as(u16, x) == 1); +} |
