From 0c855204970b6b8f31446b9c8b1b88091b14c916 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 12 May 2020 22:12:50 +0200 Subject: [PATCH] :bug: Fix slice --- src/emit/emit.c | 2 +- src/lib/array.c | 6 +++++- src/parse/check.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 7846646f..7d9cf851 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -429,7 +429,7 @@ ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice* range) { const Symbol sym = insert_symbol("@slice"); const Exp e = range->range->start ?: range->range->end; struct Op_Import opi = { .op=sym, .lhs=e->info->type, .rhs=range->base->info->type, - .pos=e->pos, .data=(uintptr_t)range->base, .op_type=op_exp }; + .pos=e->pos, .data=(uintptr_t)exp_self(range), .op_type=op_exp }; CHECK_OB(op_emit(emit, &opi)) return GW_OK; } diff --git a/src/lib/array.c b/src/lib/array.c index 1808730b..d203d71e 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -196,7 +196,8 @@ static OP_CHECK(opck_array_cast) { static OP_CHECK(opck_array_slice) { const Exp e = (Exp)data; - return e->info->type; + exp_setmeta(exp_self(e), 1); + return e->d.exp_slice.base->info->type; } static inline m_bool bounds(const M_Vector v, const m_int i) { @@ -339,6 +340,9 @@ GWION_IMPORT(array) { GWI_BB(gwi_oper_ini(gwi, "@Array", "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_at)) GWI_BB(gwi_oper_end(gwi, "@=>", ObjectAssign)) + GWI_BB(gwi_oper_ini(gwi, "@null", "@Array", NULL)) + GWI_BB(gwi_oper_add(gwi, opck_array_at)) + GWI_BB(gwi_oper_end(gwi, "@=>", ObjectAssign)) GWI_BB(gwi_oper_ini(gwi, "nonnull @Array", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_shift)) GWI_BB(gwi_oper_emi(gwi, opem_array_shift)) diff --git a/src/parse/check.c b/src/parse/check.c index 9270a82d..65666927 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -369,7 +369,7 @@ static ANN Type check_exp_slice(const Env env, const Exp_Slice* range) { const Symbol sym = insert_symbol("@slice"); const Exp e = range->range->start ?: range->range->end; struct Op_Import opi = { .op=sym, .lhs=e->info->type, .rhs=range->base->info->type, - .pos=e->pos, .data=(uintptr_t)range->base, .op_type=op_exp }; + .pos=e->pos, .data=(uintptr_t)exp_self(range), .op_type=op_exp }; return op_check(env, &opi); } -- 2.43.0