We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to test this code:
const assert = @import("std").debug.assert; inline fn sgn(n: i64) i8 { return if (n < 0) -1 else if (n == 0) 0 else 1; } test "sign function" { assert(sgn(49) == 1); assert(sgn(-49) == -1); assert(sgn(0) == 0); }
results in a compilation error:
$ zig test bug.zig ./bug.zig:6:10: error: values of type 'comptime_int' must be comptime known else if (n == 0)
Note that rewriting the above to not use an expression-based if statement does not provoke an error:
const assert = @import("std").debug.assert; inline fn sgn(n: i64) i8 { if (n < 0) return -1 else if (n == 0) return 0 else return 1; } test "sign function" { assert(sgn(49) == 1); assert(sgn(-49) == -1); assert(sgn(0) == 0); }
zig test nobug.zig All 1 tests passed.
The text was updated successfully, but these errors were encountered:
Duplicate of #5557, #3750, #4255 and. #4629
Sorry, something went wrong.
enum literal
No branches or pull requests
Trying to test this code:
results in a compilation error:
Note that rewriting the above to not use an expression-based if statement does not provoke an error:
The text was updated successfully, but these errors were encountered: