From 8915883cf627c12a7e6da9bb813d456407ebb091 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 24 Dec 2015 13:25:54 -0700 Subject: [PATCH] add error for byvalue struct param on exported fn --- src/analyze.cpp | 6 ++++++ test/run_tests.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/analyze.cpp b/src/analyze.cpp index 3e990afac593312559d2f64df1f2d3552c481a76..a05b064364aef656fca824d34c8877e998b67f24 100644 --- a/src/analyze.cpp +++ b/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(1); buf_init_from_buf(&variable_entry->name, ¶m_decl->name); variable_entry->type = type; diff --git a/test/run_tests.cpp b/test/run_tests.cpp index e2642d51281c8a7fe0bf6124a06f9aa48772de02..f5f814de8b132c1df166b02eced1d3d144202d3c 100644 --- a/test/run_tests.cpp +++ b/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) { -- 2.54.0