From 51a66c95031748444e453c3fb4fd438e3e2bbc58 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 22 Oct 2019 17:12:40 +0200 Subject: [PATCH] :art: Test mk_type --- src/lib/import.c | 10 +++++++--- tests/import/mk_type_array.c | 20 ++++++++++++++++++++ tests/sh/import.sh | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/import/mk_type_array.c diff --git a/src/lib/import.c b/src/lib/import.c index b61f37b9..8a63647c 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -240,8 +240,12 @@ ANN static m_bool mk_xtor(MemPool p, const Type type, const m_uint d, const ae_f } ANN2(1,2) Type gwi_mk_type(const Gwi gwi NUSED, const m_str name, const m_uint size, const m_str parent_name) { - m_uint depth; - const Type_Decl* td = parent_name ? str2decl(gwi->gwion->env, parent_name, &depth, gwi->loc) : NULL; + m_uint depth = 0; + Type_Decl* td = parent_name ? str2decl(gwi->gwion->env, parent_name, &depth, gwi->loc) : NULL; + if(depth) { + free_type_decl(gwi->gwion->mp, td); + GWI_ERR_O(_("can't create a type with explicit array parent. use typedef for that")) + } const Type parent = td ? known_type(gwi->gwion->env, td) : NULL; const Type t = new_type(gwi->gwion->mp, 0, name, parent); t->size = size; @@ -509,7 +513,7 @@ ANN static Arg_List make_dll_arg_list(const Gwi gwi, DL_Func * dl_fun) { return arg_list; } -ANN Type_Decl* import_td(const Gwi gwi, const m_str name) { +ANN static Type_Decl* import_td(const Gwi gwi, const m_str name) { const Env env = gwi->gwion->env; m_uint array_depth; DECL_OO(const ID_List, type_path, = str2list(env, name, &array_depth, gwi->loc)) diff --git a/tests/import/mk_type_array.c b/tests/import/mk_type_array.c new file mode 100644 index 00000000..46ca5571 --- /dev/null +++ b/tests/import/mk_type_array.c @@ -0,0 +1,20 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" + +MFUN(test_mfun){} +GWION_IMPORT(begin_class) { + Type t_invalid_var_name; + GWI_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, "Object[]"))) + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index 3c7baa29..1ddfbb7f 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #64 +# [test] #65 n=0 [ "$1" ] && n="$1" -- 2.43.0