diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-02 19:20:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-02 19:35:02 -0700 |
| commit | d3de73739f88daa05cc7a93f12c262b27a987182 (patch) | |
| tree | a5b2835b1bf22aff2fa172d448a33ad901eb348c | |
| parent | 8058b5e0a92e4eac05ba19aabed1fc041353c69b (diff) | |
| download | zig-d3de73739f88daa05cc7a93f12c262b27a987182.tar.gz zig-d3de73739f88daa05cc7a93f12c262b27a987182.zip | |
fix various semantic analyzer crashes
| -rw-r--r-- | src/analyze.cpp | 13 | ||||
| -rw-r--r-- | test/run_tests.cpp | 8 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index c093f551f1..1010ff70d7 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2736,7 +2736,9 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import, TypeTableEntry *expected_rhs_type = analyze_lvalue(g, import, context, lhs_node, LValPurposeAssign, false); - if (!is_op_allowed(expected_rhs_type, node->data.bin_op_expr.bin_op)) { + if (expected_rhs_type->id == TypeTableEntryIdInvalid) { + return g->builtin_types.entry_invalid; + } else if (!is_op_allowed(expected_rhs_type, node->data.bin_op_expr.bin_op)) { if (expected_rhs_type->id != TypeTableEntryIdInvalid) { add_node_error(g, lhs_node, buf_sprintf("operator not allowed for type '%s'", @@ -3001,7 +3003,9 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa } TypeTableEntry *implicit_type = nullptr; - if (variable_declaration->expr) { + if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) { + implicit_type = explicit_type; + } else if (variable_declaration->expr) { implicit_type = analyze_expression(g, import, context, explicit_type, variable_declaration->expr); if (implicit_type->id == TypeTableEntryIdInvalid) { // ignore the poison value @@ -3912,6 +3916,10 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import, { assert(node->type == NodeTypeFnCallExpr); + if (fn_type->id == TypeTableEntryIdInvalid) { + return fn_type; + } + // count parameters int src_param_count = fn_type->data.fn.fn_type_id.param_count; 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 static TypeTableEntry *analyze_expression(CodeGen *g, ImportTableEntry *import, BlockContext *context, TypeTableEntry *expected_type, AstNode *node) { + assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid); TypeTableEntry *return_type = nullptr; switch (node->type) { case NodeTypeBlock: diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 946f55f9fd..b8cc6fc210 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1718,14 +1718,10 @@ fn f() { i[i] = i[i]; bad[bad] = bad[bad]; } - )SOURCE", 8, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'", + )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'", ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'", - ".tmp_source.zig:4:12: error: use of undeclared identifier 'i'", - ".tmp_source.zig:4:14: error: use of undeclared identifier 'i'", ".tmp_source.zig:5:8: error: array access of non-array", - ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'", - ".tmp_source.zig:5:19: error: array access of non-array", - ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'"); + ".tmp_source.zig:5:9: error: expected type 'isize', got 'bool'"); add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( fn f(...) {} |
