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.
This commit is contained in:
John Schmidt
2022-02-06 22:11:41 +01:00
committed by Andrew Kelley
parent adc9a282d8
commit fd1284ebd0
2 changed files with 40 additions and 8 deletions

View File

@@ -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);
}