aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-05-06 23:13:12 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-05-06 23:13:12 -0400
commit157af4332a7b78672ff8ad76a00120455547e2fd (patch)
tree0e75d0d9bb111f8e778587a2fb547b74a17c5aa1 /test/compile_errors.zig
parent866c841dd8770bcc12af0aaf946c80819f5e0092 (diff)
downloadzig-157af4332a7b78672ff8ad76a00120455547e2fd.tar.gz
zig-157af4332a7b78672ff8ad76a00120455547e2fd.zip
builtin functions for division and remainder division
* add `@divTrunc` and `@divFloor` functions * add `@rem` and `@mod` functions * add compile error for `/` and `%` with signed integers * add `.bit_count` for float primitive types closes #217
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig18
1 files changed, 16 insertions, 2 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index f021898763..ff4003819a 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -702,7 +702,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("division by zero",
\\const lit_int_x = 1 / 0;
\\const lit_float_x = 1.0 / 0.0;
- \\const int_x = i32(1) / i32(0);
+ \\const int_x = u32(1) / u32(0);
\\const float_x = f32(1.0) / f32(0.0);
\\
\\export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }
@@ -792,7 +792,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
cases.add("compile time division by zero",
\\const y = foo(0);
- \\fn foo(x: i32) -> i32 {
+ \\fn foo(x: u32) -> u32 {
\\ 1 / x
\\}
\\
@@ -1709,4 +1709,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\extern fn quux(usize);
,
".tmp_source.zig:4:8: error: unable to inline function");
+
+ cases.add("signed integer division",
+ \\export fn foo(a: i32, b: i32) -> i32 {
+ \\ a / b
+ \\}
+ ,
+ ".tmp_source.zig:2:7: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
+
+ cases.add("signed integer remainder division",
+ \\export fn foo(a: i32, b: i32) -> i32 {
+ \\ a % b
+ \\}
+ ,
+ ".tmp_source.zig:2:7: error: remainder division with 'i32' and 'i32': signed integers must use @rem or @mod");
}