authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 19:09:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 19:09:17-05:00
log25a670d74e16463c7a8f91c3af91f44bf52a9e27
tree976b0e279fe21ca7407356cdf804c5cbb49b52a2
parentde9ecaf96470c9d2b9f165608a57ba03c9c0f17c

pass more tests


5 files changed, 37 insertions(+), 17 deletions(-)

src/all_types.hpp+1
......@@ -1022,6 +1022,7 @@ struct FnTableEntry {
10221022 IrExecutable analyzed_executable;
10231023 size_t prealloc_bbc;
10241024 AstNode **param_source_nodes;
1025 Buf **param_names;
10251026
10261027 AstNode *fn_no_inline_set_node;
10271028 AstNode *fn_export_set_node;
src/ast_render.cpp+4-1
......@@ -902,10 +902,13 @@ static void ast_render_tld_fn(AstRender *ar, TldFn *tld_fn) {
902902 fprintf(ar->f, "%s%s%s%sfn %s(", visib_mod_str, extern_str, coldcc_str, nakedcc_str, buf_ptr(&fn_entry->symbol_name));
903903 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
904904 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
905 if (i != 0) {
906 fprintf(ar->f, ", ");
907 }
905908 if (param_info->is_noalias) {
906909 fprintf(ar->f, "noalias ");
907910 }
908 fprintf(ar->f, "arg_%zu: %s", i, buf_ptr(&param_info->type->name));
911 fprintf(ar->f, "%s: %s", buf_ptr(tld_fn->fn_entry->param_names[i]), buf_ptr(&param_info->type->name));
909912 }
910913 if (fn_type_id->return_type->id == TypeTableEntryIdVoid) {
911914 fprintf(ar->f, ");\n");
src/ir.cpp+6
......@@ -8471,6 +8471,9 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
84718471 FnTableEntry *fn_entry = tld_fn->fn_entry;
84728472 assert(fn_entry->type_entry);
84738473
8474 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)
8475 return ira->codegen->builtin_types.entry_invalid;
8476
84748477 // TODO instead of allocating this every time, put it in the tld value and we can reference
84758478 // the same one every time
84768479 ConstExprValue *const_val = allocate<ConstExprValue>(1);
......@@ -8568,6 +8571,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
85688571 } else if (is_container(child_type)) {
85698572 if (child_type->id == TypeTableEntryIdEnum) {
85708573 ensure_complete_type(ira->codegen, child_type);
8574 if (child_type->data.enumeration.is_invalid)
8575 return ira->codegen->builtin_types.entry_invalid;
8576
85718577 TypeEnumField *field = find_enum_type_field(child_type, field_name);
85728578 if (field) {
85738579 if (field->type_entry->id == TypeTableEntryIdVoid) {
src/parseh.cpp+14
......@@ -618,6 +618,20 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
618618
619619 assert(!fn_type->data.fn.fn_type_id.is_naked);
620620
621 size_t arg_count = fn_type->data.fn.fn_type_id.param_count;
622 fn_entry->param_names = allocate<Buf *>(arg_count);
623 Buf *name_buf;
624 for (size_t i = 0; i < arg_count; i += 1) {
625 const ParmVarDecl *param = fn_decl->getParamDecl(i);
626 const char *name = decl_name(param);
627 if (strlen(name) == 0) {
628 name_buf = buf_sprintf("arg%zu", i);
629 } else {
630 name_buf = buf_create_from_str(name);
631 }
632 fn_entry->param_names[i] = name_buf;
633 }
634
621635 TldFn *tld_fn = allocate<TldFn>(1);
622636 parseh_init_tld(c, &tld_fn->base, TldIdFn, fn_name);
623637 tld_fn->fn_entry = fn_entry;
test/run_tests.cpp+12-16
......@@ -1486,11 +1486,11 @@ pub fn f() {
14861486pub fn main(args: [][]bogus) -> %void {}
14871487 )SOURCE", 1, ".tmp_source.zig:2:23: error: use of undeclared identifier 'bogus'");
14881488
1489 add_compile_fail_case("main function with bogus args type", R"SOURCE(
1489 add_compile_fail_case("for loop missing element param", R"SOURCE(
14901490fn foo(blah: []u8) {
14911491 for (blah) { }
14921492}
1493 )SOURCE", 1, ".tmp_source.zig:3:16: error: for loop expression missing element parameter");
1493 )SOURCE", 1, ".tmp_source.zig:3:5: error: for loop expression missing element parameter");
14941494
14951495 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(
14961496const JasonHM = u8;
......@@ -1511,14 +1511,14 @@ const JsonType = enum {
15111511 JSONObject,
15121512};
15131513
1514pub struct JsonNode {
1514pub const JsonNode = struct {
15151515 kind: JsonType,
15161516 jobject: ?JsonOA,
1517}
1517};
15181518
15191519fn foo() {
15201520 var jll: JasonList = undefined;
1521 jll.init(&debug.global_allocator);
1521 jll.init(1234);
15221522 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
15231523}
15241524 )SOURCE", 2,
......@@ -1526,7 +1526,7 @@ fn foo() {
15261526 ".tmp_source.zig:27:8: error: no member named 'init' in 'JsonNode'");
15271527
15281528 add_compile_fail_case("method call with first arg type primitive", R"SOURCE(
1529const Foo = {
1529const Foo = struct {
15301530 x: i32,
15311531
15321532 fn init(x: i32) -> Foo {
......@@ -1541,12 +1541,10 @@ fn f() {
15411541
15421542 derp.init();
15431543}
1544 )SOURCE", 2,
1545 ".tmp_source.zig:15:14: error: function called as method of 'Foo', but first parameter is of type 'i32'",
1546 ".tmp_source.zig:5:5: note: function declared here");
1544 )SOURCE", 1, ".tmp_source.zig:15:5: error: expected type 'i32', found '&const Foo'");
15471545
15481546 add_compile_fail_case("method call with first arg type wrong container", R"SOURCE(
1549pub struct List {
1547pub const List = struct {
15501548 len: usize,
15511549 allocator: &Allocator,
15521550
......@@ -1556,23 +1554,21 @@ pub struct List {
15561554 .allocator = allocator,
15571555 }
15581556 }
1559}
1557};
15601558
15611559pub var global_allocator = Allocator {
15621560 .field = 1234,
15631561};
15641562
1565pub struct Allocator {
1563pub const Allocator = struct {
15661564 field: i32,
1567}
1565};
15681566
15691567fn foo() {
15701568 var x = List.init(&global_allocator);
15711569 x.init();
15721570}
1573 )SOURCE", 2,
1574 ".tmp_source.zig:24:11: error: function called as method of 'List', but first parameter is of type '&Allocator'",
1575 ".tmp_source.zig:6:9: note: function declared here");
1571 )SOURCE", 1, ".tmp_source.zig:24:5: error: expected type '&Allocator', found '&List'");
15761572
15771573 add_compile_fail_case("binary not on number literal", R"SOURCE(
15781574const TINY_QUANTUM_SHIFT = 4;