From: Jérémie Astor Date: Thu, 10 Sep 2020 21:47:41 +0000 (+0200) Subject: :art: More type_cheking improvment X-Git-Tag: nightly~1350 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7b17e5ad45294bb4e4455accf12e82609ec0235c;p=gwion.git :art: More type_cheking improvment --- diff --git a/src/parse/check.c b/src/parse/check.c index 18381e03..b00a7330 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -106,7 +106,7 @@ ANN static inline void clear_decl(const Env env, const Exp_Decl *decl) { ANN static Type no_xid(const Env env, const Exp_Decl *decl) { CHECK_OO((((Exp_Decl*)decl)->type = check_td(env, decl->td))) - clear_decl(env, decl); +// clear_decl(env, decl); CHECK_BO(traverse_exp(env, exp_self(decl))) return decl->type; } @@ -169,7 +169,6 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { if(!decl->td->xid) 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 4f286873..ea01e2cf 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -61,6 +61,8 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { } static inline m_bool scan1_defined(const Env env, const Var_Decl var) { + if(var->value) // from a `typeof` declaration + return GW_OK; if(((!env->class_def || env->scope->depth) ? nspc_lookup_value1 : nspc_lookup_value2)(env->curr, var->xid)) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) @@ -88,7 +90,7 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { else ERR_B(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name) } - const Value v = var->value = new_value(env->gwion->mp, t, s_name(var->xid)); + const Value v = var->value = var->value ?: new_value(env->gwion->mp, t, s_name(var->xid)); if(SAFE_FLAG(env->class_def, struct) && !GET_FLAG(decl->td, static)) { v->from->offset = env->class_def->size; env->class_def->size += t->size;