authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-24 13:25:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-24 13:25:54-07:00
log8915883cf627c12a7e6da9bb813d456407ebb091
treee940326978476e284ed7e9565bd806f0e943524f
parent4e52281142c80230e1c60ece2824656dd08afcbd

add error for byvalue struct param on exported fn


2 files changed, 11 insertions(+), 0 deletions(-)

src/analyze.cpp+6
...@@ -1653,6 +1653,7 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,...@@ -1653,6 +1653,7 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
1653 node->codegen_node->data.fn_def_node.block_context = context;1653 node->codegen_node->data.fn_def_node.block_context = context;
16541654
1655 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;1655 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;
1656 bool is_exported = (fn_proto->visib_mod == FnProtoVisibModExport);
1656 for (int i = 0; i < fn_proto->params.length; i += 1) {1657 for (int i = 0; i < fn_proto->params.length; i += 1) {
1657 AstNode *param_decl_node = fn_proto->params.at(i);1658 AstNode *param_decl_node = fn_proto->params.at(i);
1658 assert(param_decl_node->type == NodeTypeParamDecl);1659 assert(param_decl_node->type == NodeTypeParamDecl);
...@@ -1662,6 +1663,11 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,...@@ -1662,6 +1663,11 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
1662 assert(param_decl->type->type == NodeTypeType);1663 assert(param_decl->type->type == NodeTypeType);
1663 TypeTableEntry *type = param_decl->type->codegen_node->data.type_node.entry;1664 TypeTableEntry *type = param_decl->type->codegen_node->data.type_node.entry;
16641665
1666 if (is_exported && type->id == TypeTableEntryIdStruct) {
1667 add_node_error(g, param_decl_node,
1668 buf_sprintf("byvalue struct parameters not yet supported on exported functions"));
1669 }
1670
1665 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);1671 VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
1666 buf_init_from_buf(&variable_entry->name, &param_decl->name);1672 buf_init_from_buf(&variable_entry->name, &param_decl->name);
1667 variable_entry->type = type;1673 variable_entry->type = type;
test/run_tests.cpp+5
...@@ -872,6 +872,11 @@ fn f() {...@@ -872,6 +872,11 @@ fn f() {
872struct A { x : i32, }872struct A { x : i32, }
873struct A { y : i32, }873struct A { y : i32, }
874 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'A'");874 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'A'");
875
876 add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
877struct A { x : i32, }
878export fn f(a : A) {}
879 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions");
875}880}
876881
877static void print_compiler_invocation(TestCase *test_case) {882static void print_compiler_invocation(TestCase *test_case) {