authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-02 19:20:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-02 19:35:02-07:00
logd3de73739f88daa05cc7a93f12c262b27a987182
treea5b2835b1bf22aff2fa172d448a33ad901eb348c
parent8058b5e0a92e4eac05ba19aabed1fc041353c69b

fix various semantic analyzer crashes


2 files changed, 13 insertions(+), 8 deletions(-)

src/analyze.cpp+11-2
......@@ -2736,7 +2736,9 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
27362736
27372737 TypeTableEntry *expected_rhs_type = analyze_lvalue(g, import, context, lhs_node,
27382738 LValPurposeAssign, false);
2739 if (!is_op_allowed(expected_rhs_type, node->data.bin_op_expr.bin_op)) {
2739 if (expected_rhs_type->id == TypeTableEntryIdInvalid) {
2740 return g->builtin_types.entry_invalid;
2741 } else if (!is_op_allowed(expected_rhs_type, node->data.bin_op_expr.bin_op)) {
27402742 if (expected_rhs_type->id != TypeTableEntryIdInvalid) {
27412743 add_node_error(g, lhs_node,
27422744 buf_sprintf("operator not allowed for type '%s'",
......@@ -3001,7 +3003,9 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa
30013003 }
30023004
30033005 TypeTableEntry *implicit_type = nullptr;
3004 if (variable_declaration->expr) {
3006 if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) {
3007 implicit_type = explicit_type;
3008 } else if (variable_declaration->expr) {
30053009 implicit_type = analyze_expression(g, import, context, explicit_type, variable_declaration->expr);
30063010 if (implicit_type->id == TypeTableEntryIdInvalid) {
30073011 // ignore the poison value
......@@ -3912,6 +3916,10 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
39123916{
39133917 assert(node->type == NodeTypeFnCallExpr);
39143918
3919 if (fn_type->id == TypeTableEntryIdInvalid) {
3920 return fn_type;
3921 }
3922
39153923 // count parameters
39163924 int src_param_count = fn_type->data.fn.fn_type_id.param_count;
39173925 int actual_param_count = node->data.fn_call_expr.params.length;
......@@ -4478,6 +4486,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
44784486static TypeTableEntry *analyze_expression(CodeGen *g, ImportTableEntry *import, BlockContext *context,
44794487 TypeTableEntry *expected_type, AstNode *node)
44804488{
4489 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
44814490 TypeTableEntry *return_type = nullptr;
44824491 switch (node->type) {
44834492 case NodeTypeBlock:
test/run_tests.cpp+2-6
......@@ -1718,14 +1718,10 @@ fn f() {
17181718 i[i] = i[i];
17191719 bad[bad] = bad[bad];
17201720}
1721 )SOURCE", 8, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",
1721 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",
17221722 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",
1723 ".tmp_source.zig:4:12: error: use of undeclared identifier 'i'",
1724 ".tmp_source.zig:4:14: error: use of undeclared identifier 'i'",
17251723 ".tmp_source.zig:5:8: error: array access of non-array",
1726 ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'",
1727 ".tmp_source.zig:5:19: error: array access of non-array",
1728 ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'");
1724 ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'");
17291725
17301726 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
17311727fn f(...) {}