Make it more obvious that ifs are expressions

master
MateuszOkulus 2019-12-28 16:59:47 +01:00 committed by Andrew Kelley
parent 25e71216c4
commit 6c3ccea29b
1 changed files with 8 additions and 4 deletions

View File

@ -3714,6 +3714,14 @@ fn typeNameLength(comptime T: type) usize {
const assert = @import("std").debug.assert;
test "if expression" {
// If expressions are used instead of a ternary expression.
const a: u32 = 5;
const b: u32 = 4;
const result = if (a != b) 47 else 3089;
assert(result == 47);
}
test "if boolean" {
// If expressions test boolean conditions.
const a: u32 = 5;
@ -3725,10 +3733,6 @@ test "if boolean" {
} else {
unreachable;
}
// If expressions are used instead of a ternary expression.
const result = if (a != b) 47 else 3089;
assert(result == 47);
}
test "if optional" {