From 6eca553b13bfe50b76523505f69c8ae1415a89a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sat, 5 Dec 2020 12:34:18 +0100 Subject: [PATCH] :art: Array types have unique xid --- src/env/type.c | 2 +- src/lib/array.c | 13 ------------- src/parse/check.c | 3 +++ tests/error/negative_array2.gw | 1 - 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/env/type.c b/src/env/type.c index d45e8fbb..24ae4ce4 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -100,7 +100,7 @@ ANN Type array_type(const Env env, const Type src, const m_uint depth) { const Type type = nspc_lookup_type1(src->info->owner, sym); if(type) return type; - const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, + const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(sym), env->gwion->type[et_array]); t->array_depth = depth + src->array_depth; t->info->base_type = array_base(src) ?: src; diff --git a/src/lib/array.c b/src/lib/array.c index a14cb6f4..1d8c30d6 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -317,16 +317,6 @@ static FREEARG(freearg_array) { mp_free(((Gwion)gwion)->mp, ArrayInfo, info); } -static OP_CHECK(opck_not_array) { - const Array_Sub array = (Array_Sub)data; - if(get_depth(array->type)) { - struct Array_Sub_ next = { array->exp, array->type->info->parent, array->depth }; - return check_array_access(env, &next); - } - ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"), - array->depth, get_depth(array->type)) -} - ANN Type check_array_access(const Env env, const Array_Sub array); static OP_CHECK(opck_array) { @@ -445,9 +435,6 @@ GWION_IMPORT(array) { GWI_BB(gwi_oper_add(gwi, opck_array_slice)) GWI_BB(gwi_oper_emi(gwi, opem_array_slice)) GWI_BB(gwi_oper_end(gwi, "@slice", NULL)) - GWI_BB(gwi_oper_ini(gwi, "int", (m_str)OP_ANY_TYPE, NULL)) - GWI_BB(gwi_oper_add(gwi, opck_not_array)) - GWI_BB(gwi_oper_end(gwi, "@array", NULL)) GWI_BB(gwi_oper_ini(gwi, "int", "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array)) GWI_BB(gwi_oper_emi(gwi, opem_array_access)) diff --git a/src/parse/check.c b/src/parse/check.c index 9caac831..d6e0a5d2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -385,6 +385,9 @@ ANN static Type check_prim(const Env env, Exp_Primary *prim) { } ANN Type check_array_access(const Env env, const Array_Sub array) { + if(!get_depth(array->type)) + ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"), + array->depth, get_depth(array->type)) const Symbol sym = insert_symbol("@array"); struct Op_Import opi = { .op=sym, .lhs=array->exp->info->type, .rhs=array->type, .pos=array->exp->pos, .data=(uintptr_t)array, .op_type=op_array }; diff --git a/tests/error/negative_array2.gw b/tests/error/negative_array2.gw index bc7fdf53..bda30f0c 100644 --- a/tests/error/negative_array2.gw +++ b/tests/error/negative_array2.gw @@ -1,4 +1,3 @@ #! [contains] ArrayOutofBounds var int i[2][2]; <<< i[1][-1] >>>; -<<< -1 >>>; -- 2.43.0