authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-10-28 12:15:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-10-28 12:15:37-04:00
loge4271f4fb26ce7245f73bcf9ffd33d1bd47a02e6
tree86bbcf83cf8308dbe89f85684c4fee545b11663b
parente3857a361c528d23d1a9f727619c379bea1a3563

more test coverage, change 'got' to 'found' in errors


2 files changed, 54 insertions(+), 49 deletions(-)

src/analyze.cpp+33-33
...@@ -887,7 +887,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) {...@@ -887,7 +887,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) {
887 } else if (expr->type_entry->id == TypeTableEntryIdMetaType) {887 } else if (expr->type_entry->id == TypeTableEntryIdMetaType) {
888 // OK888 // OK
889 } else {889 } else {
890 add_node_error(g, node, buf_sprintf("expected type, found expression"));890 add_node_error(g, node, buf_sprintf("expected type 'type', found '%s'", buf_ptr(&expr->type_entry->name)));
891 return g->builtin_types.entry_invalid;891 return g->builtin_types.entry_invalid;
892 }892 }
893893
...@@ -1139,7 +1139,7 @@ static FnTableEntry *resolve_const_expr_fn(CodeGen *g, ImportTableEntry *import,...@@ -1139,7 +1139,7 @@ static FnTableEntry *resolve_const_expr_fn(CodeGen *g, ImportTableEntry *import,
11391139
1140 return const_val->data.x_fn;1140 return const_val->data.x_fn;
1141 } else {1141 } else {
1142 add_node_error(g, *node, buf_sprintf("expected function, got '%s'", buf_ptr(&resolved_type->name)));1142 add_node_error(g, *node, buf_sprintf("expected function, found '%s'", buf_ptr(&resolved_type->name)));
1143 return nullptr;1143 return nullptr;
1144 }1144 }
1145}1145}
...@@ -2292,7 +2292,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *...@@ -2292,7 +2292,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *
22922292
2293 if (!reported_err) {2293 if (!reported_err) {
2294 add_node_error(g, first_executing_node(node),2294 add_node_error(g, first_executing_node(node),
2295 buf_sprintf("expected type '%s', got '%s'",2295 buf_sprintf("expected type '%s', found '%s'",
2296 buf_ptr(&expected_type->name),2296 buf_ptr(&expected_type->name),
2297 buf_ptr(&actual_type->name)));2297 buf_ptr(&actual_type->name)));
2298 }2298 }
...@@ -3564,14 +3564,14 @@ static TypeTableEntry *analyze_array_mult(CodeGen *g, ImportTableEntry *import,...@@ -3564,14 +3564,14 @@ static TypeTableEntry *analyze_array_mult(CodeGen *g, ImportTableEntry *import,
35643564
3565 if (op1_type->id != TypeTableEntryIdArray) {3565 if (op1_type->id != TypeTableEntryIdArray) {
3566 add_node_error(g, *op1,3566 add_node_error(g, *op1,
3567 buf_sprintf("expected array type, got '%s'", buf_ptr(&op1_type->name)));3567 buf_sprintf("expected array type, found '%s'", buf_ptr(&op1_type->name)));
3568 return g->builtin_types.entry_invalid;3568 return g->builtin_types.entry_invalid;
3569 }3569 }
35703570
3571 if (op2_type->id != TypeTableEntryIdNumLitInt &&3571 if (op2_type->id != TypeTableEntryIdNumLitInt &&
3572 op2_type->id != TypeTableEntryIdInt)3572 op2_type->id != TypeTableEntryIdInt)
3573 {3573 {
3574 add_node_error(g, *op2, buf_sprintf("expected integer type, got '%s'", buf_ptr(&op2_type->name)));3574 add_node_error(g, *op2, buf_sprintf("expected integer type, found '%s'", buf_ptr(&op2_type->name)));
3575 return g->builtin_types.entry_invalid;3575 return g->builtin_types.entry_invalid;
3576 }3576 }
35773577
...@@ -3750,7 +3750,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,...@@ -3750,7 +3750,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
3750 return child_type;3750 return child_type;
3751 } else {3751 } else {
3752 add_node_error(g, op1,3752 add_node_error(g, op1,
3753 buf_sprintf("expected maybe type, got '%s'",3753 buf_sprintf("expected maybe type, found '%s'",
3754 buf_ptr(&lhs_type->name)));3754 buf_ptr(&lhs_type->name)));
3755 return g->builtin_types.entry_invalid;3755 return g->builtin_types.entry_invalid;
3756 }3756 }
...@@ -3770,7 +3770,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,...@@ -3770,7 +3770,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
3770 op1_type->data.pointer.child_type == g->builtin_types.entry_u8) {3770 op1_type->data.pointer.child_type == g->builtin_types.entry_u8) {
3771 child_type = op1_type->data.pointer.child_type;3771 child_type = op1_type->data.pointer.child_type;
3772 } else {3772 } else {
3773 add_node_error(g, *op1, buf_sprintf("expected array or C string literal, got '%s'",3773 add_node_error(g, *op1, buf_sprintf("expected array or C string literal, found '%s'",
3774 buf_ptr(&op1_type->name)));3774 buf_ptr(&op1_type->name)));
3775 return g->builtin_types.entry_invalid;3775 return g->builtin_types.entry_invalid;
3776 }3776 }
...@@ -3781,7 +3781,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,...@@ -3781,7 +3781,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
3781 return g->builtin_types.entry_invalid;3781 return g->builtin_types.entry_invalid;
3782 } else if (op2_type->id == TypeTableEntryIdArray) {3782 } else if (op2_type->id == TypeTableEntryIdArray) {
3783 if (op2_type->data.array.child_type != child_type) {3783 if (op2_type->data.array.child_type != child_type) {
3784 add_node_error(g, *op2, buf_sprintf("expected array of type '%s', got '%s'",3784 add_node_error(g, *op2, buf_sprintf("expected array of type '%s', found '%s'",
3785 buf_ptr(&child_type->name),3785 buf_ptr(&child_type->name),
3786 buf_ptr(&op2_type->name)));3786 buf_ptr(&op2_type->name)));
3787 return g->builtin_types.entry_invalid;3787 return g->builtin_types.entry_invalid;
...@@ -3789,7 +3789,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,...@@ -3789,7 +3789,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
3789 } else if (op2_type->id == TypeTableEntryIdPointer &&3789 } else if (op2_type->id == TypeTableEntryIdPointer &&
3790 op2_type->data.pointer.child_type == g->builtin_types.entry_u8) {3790 op2_type->data.pointer.child_type == g->builtin_types.entry_u8) {
3791 } else {3791 } else {
3792 add_node_error(g, *op2, buf_sprintf("expected array or C string literal, got '%s'",3792 add_node_error(g, *op2, buf_sprintf("expected array or C string literal, found '%s'",
3793 buf_ptr(&op2_type->name)));3793 buf_ptr(&op2_type->name)));
3794 return g->builtin_types.entry_invalid;3794 return g->builtin_types.entry_invalid;
3795 }3795 }
...@@ -3829,12 +3829,12 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,...@@ -3829,12 +3829,12 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
3829 } else if (op1_type->id == TypeTableEntryIdPointer) {3829 } else if (op1_type->id == TypeTableEntryIdPointer) {
3830 if (!op1_val->data.x_ptr.is_c_str) {3830 if (!op1_val->data.x_ptr.is_c_str) {
3831 add_node_error(g, *op1,3831 add_node_error(g, *op1,
3832 buf_sprintf("expected array or C string literal, got '%s'",3832 buf_sprintf("expected array or C string literal, found '%s'",
3833 buf_ptr(&op1_type->name)));3833 buf_ptr(&op1_type->name)));
3834 return g->builtin_types.entry_invalid;3834 return g->builtin_types.entry_invalid;
3835 } else if (!op2_val->data.x_ptr.is_c_str) {3835 } else if (!op2_val->data.x_ptr.is_c_str) {
3836 add_node_error(g, *op2,3836 add_node_error(g, *op2,
3837 buf_sprintf("expected array or C string literal, got '%s'",3837 buf_sprintf("expected array or C string literal, found '%s'",
3838 buf_ptr(&op2_type->name)));3838 buf_ptr(&op2_type->name)));
3839 return g->builtin_types.entry_invalid;3839 return g->builtin_types.entry_invalid;
3840 }3840 }
...@@ -3951,7 +3951,7 @@ static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *i...@@ -3951,7 +3951,7 @@ static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *i
3951 return child_type;3951 return child_type;
3952 } else {3952 } else {
3953 add_node_error(g, op1,3953 add_node_error(g, op1,
3954 buf_sprintf("expected error type, got '%s'", buf_ptr(&lhs_type->name)));3954 buf_sprintf("expected error type, found '%s'", buf_ptr(&lhs_type->name)));
3955 return g->builtin_types.entry_invalid;3955 return g->builtin_types.entry_invalid;
3956 }3956 }
3957}3957}
...@@ -4976,7 +4976,7 @@ static TypeTableEntry *analyze_cmpxchg(CodeGen *g, ImportTableEntry *import,...@@ -4976,7 +4976,7 @@ static TypeTableEntry *analyze_cmpxchg(CodeGen *g, ImportTableEntry *import,
4976 return g->builtin_types.entry_invalid;4976 return g->builtin_types.entry_invalid;
4977 } else if (ptr_type->id != TypeTableEntryIdPointer) {4977 } else if (ptr_type->id != TypeTableEntryIdPointer) {
4978 add_node_error(g, *ptr_arg,4978 add_node_error(g, *ptr_arg,
4979 buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&ptr_type->name)));4979 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr_type->name)));
4980 return g->builtin_types.entry_invalid;4980 return g->builtin_types.entry_invalid;
4981 }4981 }
49824982
...@@ -5082,7 +5082,7 @@ static TypeTableEntry *analyze_div_exact(CodeGen *g, ImportTableEntry *import,...@@ -5082,7 +5082,7 @@ static TypeTableEntry *analyze_div_exact(CodeGen *g, ImportTableEntry *import,
5082 zig_panic("TODO");5082 zig_panic("TODO");
5083 } else {5083 } else {
5084 add_node_error(g, node,5084 add_node_error(g, node,
5085 buf_sprintf("expected integer type, got '%s'", buf_ptr(&result_type->name)));5085 buf_sprintf("expected integer type, found '%s'", buf_ptr(&result_type->name)));
5086 return g->builtin_types.entry_invalid;5086 return g->builtin_types.entry_invalid;
5087 }5087 }
5088}5088}
...@@ -5102,16 +5102,16 @@ static TypeTableEntry *analyze_truncate(CodeGen *g, ImportTableEntry *import,...@@ -5102,16 +5102,16 @@ static TypeTableEntry *analyze_truncate(CodeGen *g, ImportTableEntry *import,
5102 return g->builtin_types.entry_invalid;5102 return g->builtin_types.entry_invalid;
5103 } else if (dest_type->id != TypeTableEntryIdInt) {5103 } else if (dest_type->id != TypeTableEntryIdInt) {
5104 add_node_error(g, *op1,5104 add_node_error(g, *op1,
5105 buf_sprintf("expected integer type, got '%s'", buf_ptr(&dest_type->name)));5105 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
5106 return g->builtin_types.entry_invalid;5106 return g->builtin_types.entry_invalid;
5107 } else if (src_type->id != TypeTableEntryIdInt) {5107 } else if (src_type->id != TypeTableEntryIdInt) {
5108 add_node_error(g, *op2,5108 add_node_error(g, *op2,
5109 buf_sprintf("expected integer type, got '%s'", buf_ptr(&src_type->name)));5109 buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
5110 return g->builtin_types.entry_invalid;5110 return g->builtin_types.entry_invalid;
5111 } else if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {5111 } else if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
5112 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";5112 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
5113 add_node_error(g, *op2,5113 add_node_error(g, *op2,
5114 buf_sprintf("expected %s integer type, got '%s'", sign_str, buf_ptr(&src_type->name)));5114 buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
5115 return g->builtin_types.entry_invalid;5115 return g->builtin_types.entry_invalid;
5116 } else if (src_type->data.integral.bit_count <= dest_type->data.integral.bit_count) {5116 } else if (src_type->data.integral.bit_count <= dest_type->data.integral.bit_count) {
5117 add_node_error(g, *op2,5117 add_node_error(g, *op2,
...@@ -5348,12 +5348,12 @@ static TypeTableEntry *analyze_set_debug_safety(CodeGen *g, ImportTableEntry *im...@@ -5348,12 +5348,12 @@ static TypeTableEntry *analyze_set_debug_safety(CodeGen *g, ImportTableEntry *im
5348 target_context = type_arg->data.unionation.block_context;5348 target_context = type_arg->data.unionation.block_context;
5349 } else {5349 } else {
5350 add_node_error(g, *target_node,5350 add_node_error(g, *target_node,
5351 buf_sprintf("expected scope reference, got type '%s'", buf_ptr(&type_arg->name)));5351 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
5352 return g->builtin_types.entry_invalid;5352 return g->builtin_types.entry_invalid;
5353 }5353 }
5354 } else {5354 } else {
5355 add_node_error(g, *target_node,5355 add_node_error(g, *target_node,
5356 buf_sprintf("expected scope reference, got type '%s'", buf_ptr(&target_type->name)));5356 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
5357 return g->builtin_types.entry_invalid;5357 return g->builtin_types.entry_invalid;
5358 }5358 }
53595359
...@@ -5398,7 +5398,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5398,7 +5398,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
53985398
5399 if (builtin_fn->param_count != actual_param_count) {5399 if (builtin_fn->param_count != actual_param_count) {
5400 add_node_error(g, node,5400 add_node_error(g, node,
5401 buf_sprintf("expected %zu arguments, got %zu",5401 buf_sprintf("expected %zu arguments, found %zu",
5402 builtin_fn->param_count, actual_param_count));5402 builtin_fn->param_count, actual_param_count));
5403 return g->builtin_types.entry_invalid;5403 return g->builtin_types.entry_invalid;
5404 }5404 }
...@@ -5428,7 +5428,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5428,7 +5428,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5428 result_node);5428 result_node);
5429 } else {5429 } else {
5430 add_node_error(g, type_node,5430 add_node_error(g, type_node,
5431 buf_sprintf("expected integer type, got '%s'", buf_ptr(&int_type->name)));5431 buf_sprintf("expected integer type, found '%s'", buf_ptr(&int_type->name)));
5432 }5432 }
54335433
5434 // TODO constant expression evaluation5434 // TODO constant expression evaluation
...@@ -5448,14 +5448,14 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5448,14 +5448,14 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5448 dest_type->id != TypeTableEntryIdPointer)5448 dest_type->id != TypeTableEntryIdPointer)
5449 {5449 {
5450 add_node_error(g, dest_node,5450 add_node_error(g, dest_node,
5451 buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&dest_type->name)));5451 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&dest_type->name)));
5452 }5452 }
54535453
5454 if (src_type->id != TypeTableEntryIdInvalid &&5454 if (src_type->id != TypeTableEntryIdInvalid &&
5455 src_type->id != TypeTableEntryIdPointer)5455 src_type->id != TypeTableEntryIdPointer)
5456 {5456 {
5457 add_node_error(g, src_node,5457 add_node_error(g, src_node,
5458 buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&src_type->name)));5458 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&src_type->name)));
5459 }5459 }
54605460
5461 if (dest_type->id == TypeTableEntryIdPointer &&5461 if (dest_type->id == TypeTableEntryIdPointer &&
...@@ -5486,7 +5486,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5486,7 +5486,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5486 dest_type->id != TypeTableEntryIdPointer)5486 dest_type->id != TypeTableEntryIdPointer)
5487 {5487 {
5488 add_node_error(g, dest_node,5488 add_node_error(g, dest_node,
5489 buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&dest_type->name)));5489 buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&dest_type->name)));
5490 }5490 }
54915491
5492 return builtin_fn->return_type;5492 return builtin_fn->return_type;
...@@ -5703,7 +5703,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5703,7 +5703,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5703 return resolved_type;5703 return resolved_type;
5704 } else {5704 } else {
5705 add_node_error(g, type_node,5705 add_node_error(g, type_node,
5706 buf_sprintf("expected integer type, got '%s'", buf_ptr(&int_type->name)));5706 buf_sprintf("expected integer type, found '%s'", buf_ptr(&int_type->name)));
5707 return g->builtin_types.entry_invalid;5707 return g->builtin_types.entry_invalid;
5708 }5708 }
5709 }5709 }
...@@ -5794,12 +5794,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,...@@ -5794,12 +5794,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
5794 if (call_param_count < expect_arg_count) {5794 if (call_param_count < expect_arg_count) {
5795 ok_invocation = false;5795 ok_invocation = false;
5796 add_node_error(g, node,5796 add_node_error(g, node,
5797 buf_sprintf("expected at least %zu arguments, got %zu", src_param_count, call_param_count));5797 buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));
5798 }5798 }
5799 } else if (expect_arg_count != call_param_count) {5799 } else if (expect_arg_count != call_param_count) {
5800 ok_invocation = false;5800 ok_invocation = false;
5801 add_node_error(g, node,5801 add_node_error(g, node,
5802 buf_sprintf("expected %zu arguments, got %zu", expect_arg_count, call_param_count));5802 buf_sprintf("expected %zu arguments, found %zu", expect_arg_count, call_param_count));
5803 }5803 }
58045804
5805 bool all_args_const_expr = true;5805 bool all_args_const_expr = true;
...@@ -5914,7 +5914,7 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE...@@ -5914,7 +5914,7 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
59145914
5915 if (src_param_count != call_param_count + struct_node_1_or_0) {5915 if (src_param_count != call_param_count + struct_node_1_or_0) {
5916 add_node_error(g, call_node,5916 add_node_error(g, call_node,
5917 buf_sprintf("expected %zu arguments, got %zu", src_param_count - struct_node_1_or_0, call_param_count));5917 buf_sprintf("expected %zu arguments, found %zu", src_param_count - struct_node_1_or_0, call_param_count));
5918 return g->builtin_types.entry_invalid;5918 return g->builtin_types.entry_invalid;
5919 }5919 }
59205920
...@@ -6042,7 +6042,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp...@@ -6042,7 +6042,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
60426042
6043 if (actual_param_count != expected_param_count) {6043 if (actual_param_count != expected_param_count) {
6044 add_node_error(g, first_executing_node(node),6044 add_node_error(g, first_executing_node(node),
6045 buf_sprintf("expected %zu arguments, got %zu", expected_param_count, actual_param_count));6045 buf_sprintf("expected %zu arguments, found %zu", expected_param_count, actual_param_count));
6046 return g->builtin_types.entry_invalid;6046 return g->builtin_types.entry_invalid;
6047 }6047 }
60486048
...@@ -6379,7 +6379,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo...@@ -6379,7 +6379,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
6379 return type_entry->data.error.child_type;6379 return type_entry->data.error.child_type;
6380 } else {6380 } else {
6381 add_node_error(g, *expr_node,6381 add_node_error(g, *expr_node,
6382 buf_sprintf("expected error type, got '%s'", buf_ptr(&type_entry->name)));6382 buf_sprintf("expected error type, found '%s'", buf_ptr(&type_entry->name)));
6383 return g->builtin_types.entry_invalid;6383 return g->builtin_types.entry_invalid;
6384 }6384 }
6385 }6385 }
...@@ -6393,7 +6393,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo...@@ -6393,7 +6393,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
6393 return type_entry->data.maybe.child_type;6393 return type_entry->data.maybe.child_type;
6394 } else {6394 } else {
6395 add_node_error(g, *expr_node,6395 add_node_error(g, *expr_node,
6396 buf_sprintf("expected maybe type, got '%s'", buf_ptr(&type_entry->name)));6396 buf_sprintf("expected maybe type, found '%s'", buf_ptr(&type_entry->name)));
6397 return g->builtin_types.entry_invalid;6397 return g->builtin_types.entry_invalid;
6398 }6398 }
6399 }6399 }
...@@ -6689,7 +6689,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,...@@ -6689,7 +6689,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,
6689 return resolved_type->data.error.child_type;6689 return resolved_type->data.error.child_type;
6690 } else {6690 } else {
6691 add_node_error(g, node->data.return_expr.expr,6691 add_node_error(g, node->data.return_expr.expr,
6692 buf_sprintf("expected error type, got '%s'", buf_ptr(&resolved_type->name)));6692 buf_sprintf("expected error type, found '%s'", buf_ptr(&resolved_type->name)));
6693 return g->builtin_types.entry_invalid;6693 return g->builtin_types.entry_invalid;
6694 }6694 }
6695 }6695 }
...@@ -6717,7 +6717,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,...@@ -6717,7 +6717,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,
6717 return resolved_type->data.maybe.child_type;6717 return resolved_type->data.maybe.child_type;
6718 } else {6718 } else {
6719 add_node_error(g, node->data.return_expr.expr,6719 add_node_error(g, node->data.return_expr.expr,
6720 buf_sprintf("expected maybe type, got '%s'", buf_ptr(&resolved_type->name)));6720 buf_sprintf("expected maybe type, found '%s'", buf_ptr(&resolved_type->name)));
6721 return g->builtin_types.entry_invalid;6721 return g->builtin_types.entry_invalid;
6722 }6722 }
6723 }6723 }
test/run_tests.cpp+21-16
...@@ -689,11 +689,11 @@ fn a() {}...@@ -689,11 +689,11 @@ fn a() {}
689689
690 add_compile_fail_case("unreachable with return", R"SOURCE(690 add_compile_fail_case("unreachable with return", R"SOURCE(
691fn a() -> unreachable {return;}691fn a() -> unreachable {return;}
692 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'");692 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', found 'void'");
693693
694 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(694 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
695fn a() -> i32 {}695fn a() -> i32 {}
696 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'");696 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', found 'void'");
697697
698 add_compile_fail_case("undefined function call", R"SOURCE(698 add_compile_fail_case("undefined function call", R"SOURCE(
699fn a() {699fn a() {
...@@ -706,7 +706,7 @@ fn a() {...@@ -706,7 +706,7 @@ fn a() {
706 b(1);706 b(1);
707}707}
708fn b(a: i32, b: i32, c: i32) { }708fn b(a: i32, b: i32, c: i32) { }
709 )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1");709 )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, found 1");
710710
711 add_compile_fail_case("invalid type", R"SOURCE(711 add_compile_fail_case("invalid type", R"SOURCE(
712fn a() -> bogus {}712fn a() -> bogus {}
...@@ -761,7 +761,7 @@ fn f() -> i32 {...@@ -761,7 +761,7 @@ fn f() -> i32 {
761 const a = c"a";761 const a = c"a";
762 a762 a
763}763}
764 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'");764 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', found '&const u8'");
765765
766 add_compile_fail_case("if condition is bool, not int", R"SOURCE(766 add_compile_fail_case("if condition is bool, not int", R"SOURCE(
767fn f() {767fn f() {
...@@ -819,7 +819,7 @@ fn f() {...@@ -819,7 +819,7 @@ fn f() {
819 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",819 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",
820 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",820 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",
821 ".tmp_source.zig:5:8: error: array access of non-array",821 ".tmp_source.zig:5:8: error: array access of non-array",
822 ".tmp_source.zig:5:9: error: expected type 'usize', got 'bool'");822 ".tmp_source.zig:5:9: error: expected type 'usize', found 'bool'");
823823
824 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(824 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
825fn f(...) {}825fn f(...) {}
...@@ -838,7 +838,7 @@ fn f(b: bool) {...@@ -838,7 +838,7 @@ fn f(b: bool) {
838 const x : i32 = if (b) { 1 };838 const x : i32 = if (b) { 1 };
839 const y = if (b) { i32(1) };839 const y = if (b) { i32(1) };
840}840}
841 )SOURCE", 2, ".tmp_source.zig:3:21: error: expected type 'i32', got 'void'",841 )SOURCE", 2, ".tmp_source.zig:3:21: error: expected type 'i32', found 'void'",
842 ".tmp_source.zig:4:15: error: incompatible types: 'i32' and 'void'");842 ".tmp_source.zig:4:15: error: incompatible types: 'i32' and 'void'");
843843
844 add_compile_fail_case("direct struct loop", R"SOURCE(844 add_compile_fail_case("direct struct loop", R"SOURCE(
...@@ -1014,7 +1014,7 @@ const x = foo();...@@ -1014,7 +1014,7 @@ const x = foo();
1014fn f(s: []u8) -> []u8 {1014fn f(s: []u8) -> []u8 {
1015 s ++ "foo"1015 s ++ "foo"
1016}1016}
1017 )SOURCE", 1, ".tmp_source.zig:3:5: error: expected array or C string literal, got '[]u8'");1017 )SOURCE", 1, ".tmp_source.zig:3:5: error: expected array or C string literal, found '[]u8'");
10181018
1019 add_compile_fail_case("non compile time array concatenation", R"SOURCE(1019 add_compile_fail_case("non compile time array concatenation", R"SOURCE(
1020fn f(s: [10]u8) -> []u8 {1020fn f(s: [10]u8) -> []u8 {
...@@ -1069,7 +1069,7 @@ const members = []member_fn_type {...@@ -1069,7 +1069,7 @@ const members = []member_fn_type {
1069fn f(foo: Foo, index: i32) {1069fn f(foo: Foo, index: i32) {
1070 const result = members[index]();1070 const result = members[index]();
1071}1071}
1072 )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, got 0");1072 )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, found 0");
10731073
1074 add_compile_fail_case("missing function name and param name", R"SOURCE(1074 add_compile_fail_case("missing function name and param name", R"SOURCE(
1075fn () {}1075fn () {}
...@@ -1084,22 +1084,22 @@ fn a() -> i32 {0}...@@ -1084,22 +1084,22 @@ fn a() -> i32 {0}
1084fn b() -> i32 {1}1084fn b() -> i32 {1}
1085fn c() -> i32 {2}1085fn c() -> i32 {2}
1086 )SOURCE", 3,1086 )SOURCE", 3,
1087 ".tmp_source.zig:2:21: error: expected type 'fn()', got 'fn() -> i32'",1087 ".tmp_source.zig:2:21: error: expected type 'fn()', found 'fn() -> i32'",
1088 ".tmp_source.zig:2:24: error: expected type 'fn()', got 'fn() -> i32'",1088 ".tmp_source.zig:2:24: error: expected type 'fn()', found 'fn() -> i32'",
1089 ".tmp_source.zig:2:27: error: expected type 'fn()', got 'fn() -> i32'");1089 ".tmp_source.zig:2:27: error: expected type 'fn()', found 'fn() -> i32'");
10901090
1091 add_compile_fail_case("extern function pointer mismatch", R"SOURCE(1091 add_compile_fail_case("extern function pointer mismatch", R"SOURCE(
1092const fns = [](fn(i32)->i32){ a, b, c };1092const fns = [](fn(i32)->i32){ a, b, c };
1093pub fn a(x: i32) -> i32 {x + 0}1093pub fn a(x: i32) -> i32 {x + 0}
1094pub fn b(x: i32) -> i32 {x + 1}1094pub fn b(x: i32) -> i32 {x + 1}
1095export fn c(x: i32) -> i32 {x + 2}1095export fn c(x: i32) -> i32 {x + 2}
1096 )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', got 'extern fn(i32) -> i32'");1096 )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
10971097
10981098
1099 add_compile_fail_case("implicit cast from f64 to f32", R"SOURCE(1099 add_compile_fail_case("implicit cast from f64 to f32", R"SOURCE(
1100const x : f64 = 1.0;1100const x : f64 = 1.0;
1101const y : f32 = x;1101const y : f32 = x;
1102 )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', got 'f64'");1102 )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', found 'f64'");
11031103
11041104
1105 add_compile_fail_case("colliding invalid top level functions", R"SOURCE(1105 add_compile_fail_case("colliding invalid top level functions", R"SOURCE(
...@@ -1221,7 +1221,7 @@ fn derp(){}...@@ -1221,7 +1221,7 @@ fn derp(){}
12211221
1222 add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(1222 add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(
1223const a: &u8 = null;1223const a: &u8 = null;
1224 )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', got '(null)'");1224 )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', found '(null)'");
12251225
1226 add_compile_fail_case("indexing an array of size zero", R"SOURCE(1226 add_compile_fail_case("indexing an array of size zero", R"SOURCE(
1227const array = []u8{};1227const array = []u8{};
...@@ -1383,7 +1383,7 @@ fn f() {...@@ -1383,7 +1383,7 @@ fn f() {
1383 const x: u32 = 10;1383 const x: u32 = 10;
1384 @truncate(i8, x);1384 @truncate(i8, x);
1385}1385}
1386 )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, got 'u32'");1386 )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'");
13871387
1388 add_compile_fail_case("truncate same bit count", R"SOURCE(1388 add_compile_fail_case("truncate same bit count", R"SOURCE(
1389fn f() {1389fn f() {
...@@ -1493,7 +1493,7 @@ fn f(foo: &const Foo) {...@@ -1493,7 +1493,7 @@ fn f(foo: &const Foo) {
14931493
1494 foo.method(1, 2);1494 foo.method(1, 2);
1495}1495}
1496 )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 1 arguments, got 2");1496 )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 1 arguments, found 2");
14971497
1498 add_compile_fail_case("assign through constant pointer", R"SOURCE(1498 add_compile_fail_case("assign through constant pointer", R"SOURCE(
1499fn f() {1499fn f() {
...@@ -1623,6 +1623,11 @@ fn privateFunction() { }...@@ -1623,6 +1623,11 @@ fn privateFunction() { }
1623 )SOURCE");1623 )SOURCE");
1624 }1624 }
16251625
1626 add_compile_fail_case("container init with non-type", R"SOURCE(
1627const zero: i32 = 0;
1628const a = zero{1};
1629 )SOURCE", 1, ".tmp_source.zig:3:11: error: expected type 'type', found 'i32'");
1630
1626}1631}
16271632
1628//////////////////////////////////////////////////////////////////////////////1633//////////////////////////////////////////////////////////////////////////////