fn is_even(n: usize) bool {
return (n % 2 == 0);
}
pub fn main() void {
const numbers = .{ 1, 2, 3, 4, 5, 6 };
inline for (numbers) |n|
if (n % 2 == 0) @compileLog(n); // 2, 4, 6
inline for (numbers) |n|
if (is_even(n)) @compileLog(n); // 1, 2, 3, 4, 5, 6
}
The first loop logs 2, 4, 6, which is expected.
The second logs 1, 2, 3, 4, 5, 6.
Why does wrapping the predicate in a function change the behaviour? I would’ve expected it to be evaluated given n is comptime known.
Version: 0.17.0-dev.956+2dca73595