aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2022-02-06 22:11:41 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-02-06 21:26:26 -0500
commitfd1284ebd07ded1c67bbaff4c14f093051e56f59 (patch)
tree3ceb66a3288aae5aa8495ff00e7af89c9561f134 /test
parentadc9a282d8b3cbe58e07c965fe40fb1dd8666bd7 (diff)
downloadzig-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.zig6
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);
+}