Commit e4271f4fb2

Andrew Kelley <superjoe30@gmail.com>
2016-10-28 18:15:21
more test coverage, change 'got' to 'found' in errors
1 parent e3857a3
Changed files (2)
src/analyze.cpp
@@ -887,7 +887,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) {
     } else if (expr->type_entry->id == TypeTableEntryIdMetaType) {
         // OK
     } else {
-        add_node_error(g, node, buf_sprintf("expected type, found expression"));
+        add_node_error(g, node, buf_sprintf("expected type 'type', found '%s'", buf_ptr(&expr->type_entry->name)));
         return g->builtin_types.entry_invalid;
     }
 
@@ -1139,7 +1139,7 @@ static FnTableEntry *resolve_const_expr_fn(CodeGen *g, ImportTableEntry *import,
 
         return const_val->data.x_fn;
     } else {
-        add_node_error(g, *node, buf_sprintf("expected function, got '%s'", buf_ptr(&resolved_type->name)));
+        add_node_error(g, *node, buf_sprintf("expected function, found '%s'", buf_ptr(&resolved_type->name)));
         return nullptr;
     }
 }
@@ -2292,7 +2292,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, ImportTableEntry *
 
     if (!reported_err) {
         add_node_error(g, first_executing_node(node),
-            buf_sprintf("expected type '%s', got '%s'",
+            buf_sprintf("expected type '%s', found '%s'",
                 buf_ptr(&expected_type->name),
                 buf_ptr(&actual_type->name)));
     }
@@ -3564,14 +3564,14 @@ static TypeTableEntry *analyze_array_mult(CodeGen *g, ImportTableEntry *import,
 
     if (op1_type->id != TypeTableEntryIdArray) {
         add_node_error(g, *op1,
-            buf_sprintf("expected array type, got '%s'", buf_ptr(&op1_type->name)));
+            buf_sprintf("expected array type, found '%s'", buf_ptr(&op1_type->name)));
         return g->builtin_types.entry_invalid;
     }
 
     if (op2_type->id != TypeTableEntryIdNumLitInt &&
         op2_type->id != TypeTableEntryIdInt)
     {
-        add_node_error(g, *op2, buf_sprintf("expected integer type, got '%s'", buf_ptr(&op2_type->name)));
+        add_node_error(g, *op2, buf_sprintf("expected integer type, found '%s'", buf_ptr(&op2_type->name)));
         return g->builtin_types.entry_invalid;
     }
 
@@ -3750,7 +3750,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
                     return child_type;
                 } else {
                     add_node_error(g, op1,
-                        buf_sprintf("expected maybe type, got '%s'",
+                        buf_sprintf("expected maybe type, found '%s'",
                             buf_ptr(&lhs_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
@@ -3770,7 +3770,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
                            op1_type->data.pointer.child_type == g->builtin_types.entry_u8) {
                     child_type = op1_type->data.pointer.child_type;
                 } else {
-                    add_node_error(g, *op1, buf_sprintf("expected array or C string literal, got '%s'",
+                    add_node_error(g, *op1, buf_sprintf("expected array or C string literal, found '%s'",
                                 buf_ptr(&op1_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
@@ -3781,7 +3781,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
                     return g->builtin_types.entry_invalid;
                 } else if (op2_type->id == TypeTableEntryIdArray) {
                     if (op2_type->data.array.child_type != child_type) {
-                        add_node_error(g, *op2, buf_sprintf("expected array of type '%s', got '%s'",
+                        add_node_error(g, *op2, buf_sprintf("expected array of type '%s', found '%s'",
                                     buf_ptr(&child_type->name),
                                     buf_ptr(&op2_type->name)));
                         return g->builtin_types.entry_invalid;
@@ -3789,7 +3789,7 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
                 } else if (op2_type->id == TypeTableEntryIdPointer &&
                         op2_type->data.pointer.child_type == g->builtin_types.entry_u8) {
                 } else {
-                    add_node_error(g, *op2, buf_sprintf("expected array or C string literal, got '%s'",
+                    add_node_error(g, *op2, buf_sprintf("expected array or C string literal, found '%s'",
                                 buf_ptr(&op2_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
@@ -3829,12 +3829,12 @@ static TypeTableEntry *analyze_bin_op_expr(CodeGen *g, ImportTableEntry *import,
                 } else if (op1_type->id == TypeTableEntryIdPointer) {
                     if (!op1_val->data.x_ptr.is_c_str) {
                         add_node_error(g, *op1,
-                                buf_sprintf("expected array or C string literal, got '%s'",
+                                buf_sprintf("expected array or C string literal, found '%s'",
                                     buf_ptr(&op1_type->name)));
                         return g->builtin_types.entry_invalid;
                     } else if (!op2_val->data.x_ptr.is_c_str) {
                         add_node_error(g, *op2,
-                                buf_sprintf("expected array or C string literal, got '%s'",
+                                buf_sprintf("expected array or C string literal, found '%s'",
                                     buf_ptr(&op2_type->name)));
                         return g->builtin_types.entry_invalid;
                     }
@@ -3951,7 +3951,7 @@ static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *i
         return child_type;
     } else {
         add_node_error(g, op1,
-            buf_sprintf("expected error type, got '%s'", buf_ptr(&lhs_type->name)));
+            buf_sprintf("expected error type, found '%s'", buf_ptr(&lhs_type->name)));
         return g->builtin_types.entry_invalid;
     }
 }
@@ -4976,7 +4976,7 @@ static TypeTableEntry *analyze_cmpxchg(CodeGen *g, ImportTableEntry *import,
         return g->builtin_types.entry_invalid;
     } else if (ptr_type->id != TypeTableEntryIdPointer) {
         add_node_error(g, *ptr_arg,
-            buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&ptr_type->name)));
+            buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&ptr_type->name)));
         return g->builtin_types.entry_invalid;
     }
 
@@ -5082,7 +5082,7 @@ static TypeTableEntry *analyze_div_exact(CodeGen *g, ImportTableEntry *import,
         zig_panic("TODO");
     } else {
         add_node_error(g, node,
-                buf_sprintf("expected integer type, got '%s'", buf_ptr(&result_type->name)));
+                buf_sprintf("expected integer type, found '%s'", buf_ptr(&result_type->name)));
         return g->builtin_types.entry_invalid;
     }
 }
@@ -5102,16 +5102,16 @@ static TypeTableEntry *analyze_truncate(CodeGen *g, ImportTableEntry *import,
         return g->builtin_types.entry_invalid;
     } else if (dest_type->id != TypeTableEntryIdInt) {
         add_node_error(g, *op1,
-                buf_sprintf("expected integer type, got '%s'", buf_ptr(&dest_type->name)));
+                buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
         return g->builtin_types.entry_invalid;
     } else if (src_type->id != TypeTableEntryIdInt) {
         add_node_error(g, *op2,
-                buf_sprintf("expected integer type, got '%s'", buf_ptr(&src_type->name)));
+                buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
         return g->builtin_types.entry_invalid;
     } else if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
         const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
         add_node_error(g, *op2,
-                buf_sprintf("expected %s integer type, got '%s'", sign_str, buf_ptr(&src_type->name)));
+                buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
         return g->builtin_types.entry_invalid;
     } else if (src_type->data.integral.bit_count <= dest_type->data.integral.bit_count) {
         add_node_error(g, *op2,
@@ -5348,12 +5348,12 @@ static TypeTableEntry *analyze_set_debug_safety(CodeGen *g, ImportTableEntry *im
             target_context = type_arg->data.unionation.block_context;
         } else {
             add_node_error(g, *target_node,
-                buf_sprintf("expected scope reference, got type '%s'", buf_ptr(&type_arg->name)));
+                buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
             return g->builtin_types.entry_invalid;
         }
     } else {
         add_node_error(g, *target_node,
-            buf_sprintf("expected scope reference, got type '%s'", buf_ptr(&target_type->name)));
+            buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
         return g->builtin_types.entry_invalid;
     }
 
@@ -5398,7 +5398,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
 
     if (builtin_fn->param_count != actual_param_count) {
         add_node_error(g, node,
-                buf_sprintf("expected %zu arguments, got %zu",
+                buf_sprintf("expected %zu arguments, found %zu",
                     builtin_fn->param_count, actual_param_count));
         return g->builtin_types.entry_invalid;
     }
@@ -5428,7 +5428,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
                             result_node);
                 } else {
                     add_node_error(g, type_node,
-                        buf_sprintf("expected integer type, got '%s'", buf_ptr(&int_type->name)));
+                        buf_sprintf("expected integer type, found '%s'", buf_ptr(&int_type->name)));
                 }
 
                 // TODO constant expression evaluation
@@ -5448,14 +5448,14 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
                     dest_type->id != TypeTableEntryIdPointer)
                 {
                     add_node_error(g, dest_node,
-                            buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&dest_type->name)));
+                            buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&dest_type->name)));
                 }
 
                 if (src_type->id != TypeTableEntryIdInvalid &&
                     src_type->id != TypeTableEntryIdPointer)
                 {
                     add_node_error(g, src_node,
-                            buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&src_type->name)));
+                            buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&src_type->name)));
                 }
 
                 if (dest_type->id == TypeTableEntryIdPointer &&
@@ -5486,7 +5486,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
                     dest_type->id != TypeTableEntryIdPointer)
                 {
                     add_node_error(g, dest_node,
-                            buf_sprintf("expected pointer argument, got '%s'", buf_ptr(&dest_type->name)));
+                            buf_sprintf("expected pointer argument, found '%s'", buf_ptr(&dest_type->name)));
                 }
 
                 return builtin_fn->return_type;
@@ -5703,7 +5703,7 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
                     return resolved_type;
                 } else {
                     add_node_error(g, type_node,
-                        buf_sprintf("expected integer type, got '%s'", buf_ptr(&int_type->name)));
+                        buf_sprintf("expected integer type, found '%s'", buf_ptr(&int_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
             }
@@ -5794,12 +5794,12 @@ static TypeTableEntry *analyze_fn_call_ptr(CodeGen *g, ImportTableEntry *import,
         if (call_param_count < expect_arg_count) {
             ok_invocation = false;
             add_node_error(g, node,
-                buf_sprintf("expected at least %zu arguments, got %zu", src_param_count, call_param_count));
+                buf_sprintf("expected at least %zu arguments, found %zu", src_param_count, call_param_count));
         }
     } else if (expect_arg_count != call_param_count) {
         ok_invocation = false;
         add_node_error(g, node,
-                buf_sprintf("expected %zu arguments, got %zu", expect_arg_count, call_param_count));
+                buf_sprintf("expected %zu arguments, found %zu", expect_arg_count, call_param_count));
     }
 
     bool all_args_const_expr = true;
@@ -5914,7 +5914,7 @@ static TypeTableEntry *analyze_fn_call_with_inline_args(CodeGen *g, ImportTableE
 
     if (src_param_count != call_param_count + struct_node_1_or_0) {
         add_node_error(g, call_node,
-            buf_sprintf("expected %zu arguments, got %zu", src_param_count - struct_node_1_or_0, call_param_count));
+            buf_sprintf("expected %zu arguments, found %zu", src_param_count - struct_node_1_or_0, call_param_count));
         return g->builtin_types.entry_invalid;
     }
 
@@ -6042,7 +6042,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
 
     if (actual_param_count != expected_param_count) {
         add_node_error(g, first_executing_node(node),
-                buf_sprintf("expected %zu arguments, got %zu", expected_param_count, actual_param_count));
+                buf_sprintf("expected %zu arguments, found %zu", expected_param_count, actual_param_count));
         return g->builtin_types.entry_invalid;
     }
 
@@ -6379,7 +6379,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
                     return type_entry->data.error.child_type;
                 } else {
                     add_node_error(g, *expr_node,
-                        buf_sprintf("expected error type, got '%s'", buf_ptr(&type_entry->name)));
+                        buf_sprintf("expected error type, found '%s'", buf_ptr(&type_entry->name)));
                     return g->builtin_types.entry_invalid;
                 }
             }
@@ -6393,7 +6393,7 @@ static TypeTableEntry *analyze_prefix_op_expr(CodeGen *g, ImportTableEntry *impo
                     return type_entry->data.maybe.child_type;
                 } else {
                     add_node_error(g, *expr_node,
-                        buf_sprintf("expected maybe type, got '%s'", buf_ptr(&type_entry->name)));
+                        buf_sprintf("expected maybe type, found '%s'", buf_ptr(&type_entry->name)));
                     return g->builtin_types.entry_invalid;
                 }
             }
@@ -6689,7 +6689,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,
                     return resolved_type->data.error.child_type;
                 } else {
                     add_node_error(g, node->data.return_expr.expr,
-                        buf_sprintf("expected error type, got '%s'", buf_ptr(&resolved_type->name)));
+                        buf_sprintf("expected error type, found '%s'", buf_ptr(&resolved_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
             }
@@ -6717,7 +6717,7 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,
                     return resolved_type->data.maybe.child_type;
                 } else {
                     add_node_error(g, node->data.return_expr.expr,
-                        buf_sprintf("expected maybe type, got '%s'", buf_ptr(&resolved_type->name)));
+                        buf_sprintf("expected maybe type, found '%s'", buf_ptr(&resolved_type->name)));
                     return g->builtin_types.entry_invalid;
                 }
             }
test/run_tests.cpp
@@ -689,11 +689,11 @@ fn a() {}
 
     add_compile_fail_case("unreachable with return", R"SOURCE(
 fn a() -> unreachable {return;}
-    )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'");
+    )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', found 'void'");
 
     add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
 fn a() -> i32 {}
-    )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'");
+    )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', found 'void'");
 
     add_compile_fail_case("undefined function call", R"SOURCE(
 fn a() {
@@ -706,7 +706,7 @@ fn a() {
     b(1);
 }
 fn b(a: i32, b: i32, c: i32) { }
-    )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1");
+    )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, found 1");
 
     add_compile_fail_case("invalid type", R"SOURCE(
 fn a() -> bogus {}
@@ -761,7 +761,7 @@ fn f() -> i32 {
     const a = c"a";
     a
 }
-    )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'");
+    )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', found '&const u8'");
 
     add_compile_fail_case("if condition is bool, not int", R"SOURCE(
 fn f() {
@@ -819,7 +819,7 @@ fn f() {
     )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:5:8: error: array access of non-array",
-                 ".tmp_source.zig:5:9: error: expected type 'usize', got 'bool'");
+                 ".tmp_source.zig:5:9: error: expected type 'usize', found 'bool'");
 
     add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
 fn f(...) {}
@@ -838,7 +838,7 @@ fn f(b: bool) {
     const x : i32 = if (b) { 1 };
     const y = if (b) { i32(1) };
 }
-    )SOURCE", 2, ".tmp_source.zig:3:21: error: expected type 'i32', got 'void'",
+    )SOURCE", 2, ".tmp_source.zig:3:21: error: expected type 'i32', found 'void'",
                  ".tmp_source.zig:4:15: error: incompatible types: 'i32' and 'void'");
 
     add_compile_fail_case("direct struct loop", R"SOURCE(
@@ -1014,7 +1014,7 @@ const x = foo();
 fn f(s: []u8) -> []u8 {
     s ++ "foo"
 }
-    )SOURCE", 1, ".tmp_source.zig:3:5: error: expected array or C string literal, got '[]u8'");
+    )SOURCE", 1, ".tmp_source.zig:3:5: error: expected array or C string literal, found '[]u8'");
 
     add_compile_fail_case("non compile time array concatenation", R"SOURCE(
 fn f(s: [10]u8) -> []u8 {
@@ -1069,7 +1069,7 @@ const members = []member_fn_type {
 fn f(foo: Foo, index: i32) {
     const result = members[index]();
 }
-    )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, got 0");
+    )SOURCE", 1, ".tmp_source.zig:21:34: error: expected 1 arguments, found 0");
 
     add_compile_fail_case("missing function name and param name", R"SOURCE(
 fn () {}
@@ -1084,22 +1084,22 @@ fn a() -> i32 {0}
 fn b() -> i32 {1}
 fn c() -> i32 {2}
     )SOURCE", 3,
-            ".tmp_source.zig:2:21: error: expected type 'fn()', got 'fn() -> i32'",
-            ".tmp_source.zig:2:24: error: expected type 'fn()', got 'fn() -> i32'",
-            ".tmp_source.zig:2:27: error: expected type 'fn()', got 'fn() -> i32'");
+            ".tmp_source.zig:2:21: error: expected type 'fn()', found 'fn() -> i32'",
+            ".tmp_source.zig:2:24: error: expected type 'fn()', found 'fn() -> i32'",
+            ".tmp_source.zig:2:27: error: expected type 'fn()', found 'fn() -> i32'");
 
     add_compile_fail_case("extern function pointer mismatch", R"SOURCE(
 const fns = [](fn(i32)->i32){ a, b, c };
 pub fn a(x: i32) -> i32 {x + 0}
 pub fn b(x: i32) -> i32 {x + 1}
 export fn c(x: i32) -> i32 {x + 2}
-    )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', got 'extern fn(i32) -> i32'");
+    )SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
 
 
     add_compile_fail_case("implicit cast from f64 to f32", R"SOURCE(
 const x : f64 = 1.0;
 const y : f32 = x;
-    )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', got 'f64'");
+    )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', found 'f64'");
 
 
     add_compile_fail_case("colliding invalid top level functions", R"SOURCE(
@@ -1221,7 +1221,7 @@ fn derp(){}
 
     add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(
 const a: &u8 = null;
-    )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', got '(null)'");
+    )SOURCE", 1, ".tmp_source.zig:2:16: error: expected type '&u8', found '(null)'");
 
     add_compile_fail_case("indexing an array of size zero", R"SOURCE(
 const array = []u8{};
@@ -1383,7 +1383,7 @@ fn f() {
     const x: u32 = 10;
     @truncate(i8, x);
 }
-    )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, got 'u32'");
+    )SOURCE", 1, ".tmp_source.zig:4:19: error: expected signed integer type, found 'u32'");
 
     add_compile_fail_case("truncate same bit count", R"SOURCE(
 fn f() {
@@ -1493,7 +1493,7 @@ fn f(foo: &const Foo) {
 
     foo.method(1, 2);
 }
-    )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 1 arguments, got 2");
+    )SOURCE", 1, ".tmp_source.zig:7:15: error: expected 1 arguments, found 2");
 
     add_compile_fail_case("assign through constant pointer", R"SOURCE(
 fn f() {
@@ -1623,6 +1623,11 @@ fn privateFunction() { }
         )SOURCE");
     }
 
+    add_compile_fail_case("container init with non-type", R"SOURCE(
+const zero: i32 = 0;
+const a = zero{1};
+    )SOURCE", 1, ".tmp_source.zig:3:11: error: expected type 'type', found 'i32'");
+
 }
 
 //////////////////////////////////////////////////////////////////////////////