Commit 8915883cf6

Andrew Kelley <superjoe30@gmail.com>
2015-12-24 21:25:54
add error for byvalue struct param on exported fn
1 parent 4e52281
Changed files (2)
src/analyze.cpp
@@ -1653,6 +1653,7 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
                 node->codegen_node->data.fn_def_node.block_context = context;
 
                 AstNodeFnProto *fn_proto = &fn_proto_node->data.fn_proto;
+                bool is_exported = (fn_proto->visib_mod == FnProtoVisibModExport);
                 for (int i = 0; i < fn_proto->params.length; i += 1) {
                     AstNode *param_decl_node = fn_proto->params.at(i);
                     assert(param_decl_node->type == NodeTypeParamDecl);
@@ -1662,6 +1663,11 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
                     assert(param_decl->type->type == NodeTypeType);
                     TypeTableEntry *type = param_decl->type->codegen_node->data.type_node.entry;
 
+                    if (is_exported && type->id == TypeTableEntryIdStruct) {
+                        add_node_error(g, param_decl_node,
+                            buf_sprintf("byvalue struct parameters not yet supported on exported functions"));
+                    }
+
                     VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
                     buf_init_from_buf(&variable_entry->name, &param_decl->name);
                     variable_entry->type = type;
test/run_tests.cpp
@@ -872,6 +872,11 @@ fn f() {
 struct A { x : i32, }
 struct A { y : i32, }
     )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'A'");
+
+    add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
+struct A { x : i32, }
+export fn f(a : A) {}
+    )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions");
 }
 
 static void print_compiler_invocation(TestCase *test_case) {