zig
zig copied to clipboard
require parentheses with shifting and arithmetic
This is a sub-task of #114.
const std = @import("std");
pub const max_ciphertext_len = 1 << 14 + 256;
test "operator precedence" {
try std.testing.expect(max_ciphertext_len == 16640);
}
Actual behavior:
$ stage3/bin/zig test test.zig
Test [1/1] test.operator precedence... FAIL (TestUnexpectedResult)
/home/andy/dev/zig/lib/std/testing.zig:509:14: 0x20bed7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/home/andy/dev/zig/build-release/test.zig:6:5: 0x20bff5 in test.operator precedence (test)
try std.testing.expect(max_ciphertext_len == 16640);
^
0 passed; 0 skipped; 1 failed.
Expected behavior:
test.zig:3:39: error: parentheses required to disambiguate operator precedence
pub const max_ciphertext_len: u16 = 1 << 14 + 256;
~~^~~~~~~~~~~