zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7f4d4bdb3f8c4ac0c368074c111d5455ea6c8ade (tree)
parent 4b68224c60d78c82515882637ede223aee48091a
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Mon, 26 Sep 2016 19:42:51 -0400

fix crash when doing binary not on integer literal

closes #201

Diffstat:
Msrc/analyze.cpp | 6++----
Mtest/run_tests.cpp | 7+++++++
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -6037,12 +6037,10 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo *expr_node); if (expr_type->id == TypeTableEntryIdInvalid) { return expr_type; - } else if (expr_type->id == TypeTableEntryIdInt || - expr_type->id == TypeTableEntryIdNumLitInt) - { + } else if (expr_type->id == TypeTableEntryIdInt) { return expr_type; } else { - add_node_error(g, *expr_node, buf_sprintf("invalid binary not type: '%s'", + add_node_error(g, node, buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); return g->builtin_types.entry_invalid; } diff --git a/test/run_tests.cpp b/test/run_tests.cpp @@ -1583,6 +1583,13 @@ fn foo() { )SOURCE", 2, ".tmp_source.zig:24:11: error: function called as method of 'List', but first parameter is of type '&Allocator'", ".tmp_source.zig:6:9: note: function declared here"); + + add_compile_fail_case("binary not on number literal", R"SOURCE( +const TINY_QUANTUM_SHIFT = 4; +const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; +var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); + )SOURCE", 1, ".tmp_source.zig:4:60: error: unable to perform binary not operation on type '(integer literal)'"); + } //////////////////////////////////////////////////////////////////////////////