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,...@@ -2736,7 +2736,9 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
27362736
2737 TypeTableEntry *expected_rhs_type = analyze_lvalue(g, import, context, lhs_node,2737 TypeTableEntry *expected_rhs_type = analyze_lvalue(g, import, context, lhs_node,
2738 LValPurposeAssign, false);2738 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)) {
2740 if (expected_rhs_type->id != TypeTableEntryIdInvalid) {2742 if (expected_rhs_type->id != TypeTableEntryIdInvalid) {
2741 add_node_error(g, lhs_node,2743 add_node_error(g, lhs_node,
2742 buf_sprintf("operator not allowed for type '%s'",2744 buf_sprintf("operator not allowed for type '%s'",
...@@ -3001,7 +3003,9 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa...@@ -3001,7 +3003,9 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa
3001 }3003 }
30023004
3003 TypeTableEntry *implicit_type = nullptr;3005 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) {
3005 implicit_type = analyze_expression(g, import, context, explicit_type, variable_declaration->expr);3009 implicit_type = analyze_expression(g, import, context, explicit_type, variable_declaration->expr);
3006 if (implicit_type->id == TypeTableEntryIdInvalid) {3010 if (implicit_type->id == TypeTableEntryIdInvalid) {
3007 // ignore the poison value3011 // ignore the poison value
...@@ -3912,6 +3916,10 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,...@@ -3912,6 +3916,10 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
3912{3916{
3913 assert(node->type == NodeTypeFnCallExpr);3917 assert(node->type == NodeTypeFnCallExpr);
39143918
3919 if (fn_type->id == TypeTableEntryIdInvalid) {
3920 return fn_type;
3921 }
3922
3915 // count parameters3923 // count parameters
3916 int src_param_count = fn_type->data.fn.fn_type_id.param_count;3924 int src_param_count = fn_type->data.fn.fn_type_id.param_count;
3917 int actual_param_count = node->data.fn_call_expr.params.length;3925 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...@@ -4478,6 +4486,7 @@ static TypeTableEntry *analyze_asm_expr(CodeGen *g, ImportTableEntry *import, Bl
4478static TypeTableEntry *analyze_expression(CodeGen *g, ImportTableEntry *import, BlockContext *context,4486static TypeTableEntry *analyze_expression(CodeGen *g, ImportTableEntry *import, BlockContext *context,
4479 TypeTableEntry *expected_type, AstNode *node)4487 TypeTableEntry *expected_type, AstNode *node)
4480{4488{
4489 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
4481 TypeTableEntry *return_type = nullptr;4490 TypeTableEntry *return_type = nullptr;
4482 switch (node->type) {4491 switch (node->type) {
4483 case NodeTypeBlock:4492 case NodeTypeBlock:
test/run_tests.cpp+2-6
...@@ -1718,14 +1718,10 @@ fn f() {...@@ -1718,14 +1718,10 @@ fn f() {
1718 i[i] = i[i];1718 i[i] = i[i];
1719 bad[bad] = bad[bad];1719 bad[bad] = bad[bad];
1720}1720}
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'",
1722 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",1722 ".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'",
1725 ".tmp_source.zig:5:8: error: array access of non-array",1723 ".tmp_source.zig:5:8: error: array access of non-array",
1726 ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'",1724 ".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'");
17291725
1730 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(1726 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
1731fn f(...) {}1727fn f(...) {}