authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-26 19:42:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-26 19:42:51-04:00
log7f4d4bdb3f8c4ac0c368074c111d5455ea6c8ade
tree1c8aef4c959a8376dae11a57646fe13b4cd377c3
parent4b68224c60d78c82515882637ede223aee48091a

fix crash when doing binary not on integer literal

closes #201

2 files changed, 9 insertions(+), 4 deletions(-)

src/analyze.cpp+2-4
...@@ -6037,12 +6037,10 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo...@@ -6037,12 +6037,10 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
6037 *expr_node);6037 *expr_node);
6038 if (expr_type->id == TypeTableEntryIdInvalid) {6038 if (expr_type->id == TypeTableEntryIdInvalid) {
6039 return expr_type;6039 return expr_type;
6040 } else if (expr_type->id == TypeTableEntryIdInt ||6040 } else if (expr_type->id == TypeTableEntryIdInt) {
6041 expr_type->id == TypeTableEntryIdNumLitInt)
6042 {
6043 return expr_type;6041 return expr_type;
6044 } else {6042 } else {
6045 add_node_error(g, *expr_node, buf_sprintf("invalid binary not type: '%s'",6043 add_node_error(g, node, buf_sprintf("unable to perform binary not operation on type '%s'",
6046 buf_ptr(&expr_type->name)));6044 buf_ptr(&expr_type->name)));
6047 return g->builtin_types.entry_invalid;6045 return g->builtin_types.entry_invalid;
6048 }6046 }
test/run_tests.cpp+7
...@@ -1583,6 +1583,13 @@ fn foo() {...@@ -1583,6 +1583,13 @@ fn foo() {
1583 )SOURCE", 2,1583 )SOURCE", 2,
1584 ".tmp_source.zig:24:11: error: function called as method of 'List', but first parameter is of type '&Allocator'",1584 ".tmp_source.zig:24:11: error: function called as method of 'List', but first parameter is of type '&Allocator'",
1585 ".tmp_source.zig:6:9: note: function declared here");1585 ".tmp_source.zig:6:9: note: function declared here");
1586
1587 add_compile_fail_case("binary not on number literal", R"SOURCE(
1588const TINY_QUANTUM_SHIFT = 4;
1589const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
1590var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
1591 )SOURCE", 1, ".tmp_source.zig:4:60: error: unable to perform binary not operation on type '(integer literal)'");
1592
1586}1593}
15871594
1588//////////////////////////////////////////////////////////////////////////////1595//////////////////////////////////////////////////////////////////////////////