From fd1284ebd07ded1c67bbaff4c14f093051e56f59 Mon Sep 17 00:00:00 2001 From: John Schmidt Date: Sun, 6 Feb 2022 22:11:41 +0100 Subject: 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. --- test/behavior/basic.zig | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') 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); +} -- cgit v1.2.3