From: fennecdjay Date: Sun, 13 Oct 2019 17:14:53 +0000 (+0200) Subject: :art: Defects X-Git-Tag: nightly~2156 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=b6f15cfdb20321743fc1958afb2af52b391aa57c;p=gwion.git :art: Defects --- diff --git a/src/lib/import.c b/src/lib/import.c index ee621c40..dc3a0727 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -607,7 +607,7 @@ ANN static Exp make_exp(const Gwi gwi, const m_str type, const m_str name) { const Env env = gwi->gwion->env; m_uint array_depth; Array_Sub array = NULL; - DECL_OO(const ID_List, id_list, = str2list(env, type, &array_depth, gwi->loc)) + CHECK_OO(const ID_List, id_list, = str2list(env, type, &array_depth, gwi->loc)) if(array_depth) { array = new_array_sub(env->gwion->mp, NULL); array->depth = array_depth; @@ -627,25 +627,33 @@ ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name) { ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) { DECL_OB(const Exp, exp, = make_exp(gwi, type, name)) - DECL_OB(const Type, t, = known_type(gwi->gwion->env, exp->d.exp_decl.td)) + const Type t = known_type(gwi->gwion->env, exp->d.exp_decl.td); + if(!t) { + free_exp(gwi->gwion->mp, exp); + return GW_ERROR; + } if(isa(t, gwi->gwion->type[et_object]) > 0) SET_FLAG(exp->d.exp_decl.td, ref); gwi->union_data.list = new_decl_list(gwi->gwion->mp, exp, gwi->union_data.list); return GW_OK; } -ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { - if(!gwi->union_data.list) - GWI_ERR_O(_("union is empty")); - const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->union_data.list, loc_cpy(gwi->gwion->mp, gwi->loc)); - udef->flag = flag; +ANN static Type union_type(const Gwi gwi, const Union_Def udef) { CHECK_BO(traverse_union_def(gwi->gwion->env, udef)) emit_union_offset(udef->l, udef->o); if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) - gwi->gwion->env->class_def->nspc->info->offset = + gwi->gwion->env->class_def->nspc->info->offset = udef->o + udef->s; - const Type t = udef->xid ? udef->value->type : + return udef->xid ? udef->value->type : udef->type_xid ? udef->type : gwi->gwion->type[et_int]; +} + +ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { + if(!gwi->union_data.list) + GWI_ERR_O(_("union is empty")); + const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->union_data.list, loc_cpy(gwi->gwion->mp, gwi->loc)); + udef->flag = flag; + const Type t = union_type(gwi, udef); free_union_def(gwi->gwion->mp, udef); gwi->union_data.list = NULL; gwi->union_data.xid = NULL; diff --git a/src/parse/check.c b/src/parse/check.c index edb47ebe..2f93a9ae 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -774,7 +774,7 @@ ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) { if(arg || e) ERR_O(exp_self(exp)->pos, _("argument number does not match for lambda")) l->def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, NULL, l->name, l->args), - l->code, 0, loc_cpy(env->gwion->mp, loc_cpy(env->gwion->mp, exp_self(exp)->pos))); + l->code, 0, loc_cpy(env->gwion->mp, exp_self(exp)->pos)); CHECK_BO(traverse_func_def(env, l->def)) if(env->class_def) SET_FLAG(l->def, member); diff --git a/tests/import/union_fail_exp.c b/tests/import/union_fail_exp.c new file mode 100644 index 00000000..7ecf58e4 --- /dev/null +++ b/tests/import/union_fail_exp.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" + +GWION_IMPORT(union_test) { + GWI_BB(gwi_union_ini(gwi, NULL)) + GWI_BB(gwi_union_add(gwi,"Float", "f")) + GWI_BB(gwi_union_add(gwi,"int", "i")) + GWI_OB(gwi_union_end(gwi, 0)) + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index 7951944e..6dd5eeba 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #54 +# [test] #55 n=0 [ "$1" ] && n="$1"