diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-11 15:02:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-11 15:02:22 -0700 |
| commit | a180168871b6e32a8c0825b1eb309587c3e0d179 (patch) | |
| tree | 935616676906c2b56d3d19f8acd6a07e86865e14 /test/run_tests.cpp | |
| parent | 2bf6c28bc3e535deb651d5b37e332226e0d38930 (diff) | |
| download | zig-a180168871b6e32a8c0825b1eb309587c3e0d179.tar.gz zig-a180168871b6e32a8c0825b1eb309587c3e0d179.zip | |
fix division by 0 crashing compiler
closes #99
closes #124
thanks to Michael Patraw for submitting a patch for this.
Diffstat (limited to 'test/run_tests.cpp')
| -rw-r--r-- | test/run_tests.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp index fc60d1a3c4..3338134196 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1740,6 +1740,26 @@ fn f() { if (true) { } } )SOURCE", 1, ".tmp_source.zig:3:9: error: condition is always true; unnecessary if statement"); + + + add_compile_fail_case("addition with non numbers", R"SOURCE( +struct Foo { + field: i32, +} +const x = Foo {.field = 1} + Foo {.field = 2}; + )SOURCE", 1, ".tmp_source.zig:5:28: error: invalid operands to binary expression: 'Foo' and 'Foo'"); + + + add_compile_fail_case("division by zero", R"SOURCE( +const lit_int_x = 1 / 0; +const lit_float_x = 1.0 / 0.0; +const int_x = i32(1) / i32(0); +const float_x = f32(1.0) / f32(0.0); + )SOURCE", 4, + ".tmp_source.zig:2:21: error: division by zero is undefined", + ".tmp_source.zig:3:25: error: division by zero is undefined", + ".tmp_source.zig:4:22: error: division by zero is undefined", + ".tmp_source.zig:5:26: error: division by zero is undefined"); } ////////////////////////////////////////////////////////////////////////////// |
