aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-19 01:32:15 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-19 01:43:43 -0400
commit987768778a67538299f84a6ab7ff0ca65f69d2ac (patch)
tree2e7551d76bf9a3e6d242a961eacf7c81aab6025f /test/compile_errors.zig
parent558ece8f6f1889bc4773432c16cdf96a54ec1431 (diff)
downloadzig-987768778a67538299f84a6ab7ff0ca65f69d2ac.tar.gz
zig-987768778a67538299f84a6ab7ff0ca65f69d2ac.zip
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7 * shift operations shift amount parameter type is integer with log2 bit width of other param - This enforces not violating undefined behavior on shift amount >= bit width with the type system * clean up math.log, math.ln, math.log2, math.log10 closes #403
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 358569d0ef..16c36dc294 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -1973,4 +1973,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\}
,
".tmp_source.zig:2:15: error: exact shift shifted out 1 bits");
+
+ cases.add("shifting without int type or comptime known",
+ \\export fn entry(x: u8) -> u8 {
+ \\ return 0x11 << x;
+ \\}
+ ,
+ ".tmp_source.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known");
+
+ cases.add("shifting RHS is log2 of LHS int bit width",
+ \\export fn entry(x: u8, y: u8) -> u8 {
+ \\ return x << y;
+ \\}
+ ,
+ ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'");
}