From ffab126948da91aeac4a25bdd851a6cd701770c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 21 May 2020 19:05:15 +0200 Subject: [PATCH] :art: Fix scan1 auto decl --- src/emit/emit.c | 8 ++++---- src/parse/check.c | 1 + src/parse/scan1.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 3263141f..0b2409e1 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -622,7 +622,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Exp_Decl *d const m_bool is_array = (array && array->exp) || GET_FLAG(decl->td, force); const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const uint emit_addr = (!is_obj || (is_ref && !is_array)) ? emit_var : 1; - if(is_obj && (is_array || !is_ref)) + if(is_obj && (is_array || !is_ref) && !GET_FLAG(v, ref)) CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) f_instr *exec = (f_instr*)allocmember; if(!GET_FLAG(v, member)) { @@ -636,7 +636,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Exp_Decl *d const Instr instr = !(SAFE_FLAG(emit->env->class_def, struct) && !emit->env->scope->depth) ? emit_kind(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1, exec) : emit_struct_decl(emit, v, !struct_ctor(v) ? emit_addr : 1); instr->m_val = v->from->offset; - if(is_obj && (is_array || !is_ref)) { + if(is_obj && (is_array || !is_ref) && !GET_FLAG(v, ref)) { emit_add_instr(emit, Assign); const size_t missing_depth = type->array_depth - (array ? array->depth : 0); if(missing_depth && !GET_FLAG(decl->td, force)) { @@ -659,14 +659,14 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, const m_bool is_array = array && array->exp; const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const uint emit_addr = (!is_obj || (is_ref && !is_array)) ? emit_var : 1; - if(is_obj && (is_array || !is_ref)) + if(is_obj && (is_array || !is_ref && !GET_FLAG(v, ref))) CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) const Instr instr = emit_kind(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1, dotstatic); v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size); SET_FLAG(v, union); instr->m_val = (m_uint)v->d.ptr; instr->m_val2 = v->type->size; - if(is_obj && (is_array || !is_ref)) { + if(is_obj && (is_array || !is_ref && !GET_FLAG(v, ref))) { const Instr assign = emit_add_instr(emit, Assign); const size_t missing_depth = type->array_depth - (array ? array->depth : 0); if(missing_depth && !GET_FLAG(decl->td, force)) { diff --git a/src/parse/check.c b/src/parse/check.c index 69e9137c..a066bbd2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -157,6 +157,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { return no_xid(env, decl); if(decl->td->xid == insert_symbol("auto")) { // should be better clear_decl(env, decl); + SET_FLAG(decl->td, ref); CHECK_BO(scan1_exp(env, exp_self(decl))) CHECK_BO(scan2_exp(env, exp_self(decl))) } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 81efcb9f..0f62b29d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -74,7 +74,7 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)) Type t = decl->type; const Value former = nspc_lookup_value0(env->curr, var->xid); - if(former && t != env->gwion->type[et_auto]) + if(former) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) if(var->array) { -- 2.43.0