From bfa35a4a61da14717ee7e7bee058d334488032be Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 11 Dec 2022 14:41:05 +0100 Subject: [PATCH] :art: declared_here() --- include/env/env.h | 3 ++- include/gwion_env.h | 5 +++++ src/env/env_utils.c | 2 +- src/parse/check.c | 6 ++---- src/parse/scan0.c | 3 +-- src/parse/scan2.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/env/env.h b/include/env/env.h index c6694309..a0b2db13 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -57,7 +57,6 @@ ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos); ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos); ANN void env_add_type(const Env, const Type, const loc_t); ANN Type find_type(const Env, Type_Decl *); -ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); ANN m_bool traverse_func_template(const Env, const Func_Def); ANN void env_err(const Env, const loc_t pos, const m_str fmt, ...); ANN void env_warn(const Env, const loc_t pos, const m_str fmt, ...); @@ -72,4 +71,6 @@ struct ScopeEffect { ANN void env_add_effect(const Env a, const Symbol effect, const loc_t pos); ANN void call_add_effect(const Env env, const Func func, const loc_t pos); + +ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); #endif diff --git a/include/gwion_env.h b/include/gwion_env.h index 00fc4804..f9c7e135 100644 --- a/include/gwion_env.h +++ b/include/gwion_env.h @@ -21,4 +21,9 @@ ANN2(1,4) static inline void gwerr_basic_from(const m_str msg, const m_str expla ANN static inline void gwerr_secondary_from(const m_str msg, const ValueFrom *from) { gwerr_secondary(msg, from->filename, from->loc); } + +ANN static inline void declared_here(const Value v) { + gwerr_secondary_from("declared here", v->from); +} #endif + diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 8f50dc1c..180e0a73 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -69,7 +69,7 @@ ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { const Value v = nspc_lookup_value0(env->curr, s); if (!v || is_class(env->gwion, v->type)) return GW_OK; gwerr_basic(_("already declared as variable"), NULL, NULL, env->name, pos, 0); - gwerr_secondary_from("declared here", v->from); + declared_here(v); env_error_footer(env); return GW_ERROR; } diff --git a/src/parse/check.c b/src/parse/check.c index a2c66076..2107d85e 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -336,7 +336,7 @@ ANN static m_bool check_upvalue(const Env env, const Exp_Primary *prim, const Va if(not_upvalue(env, v)) return GW_OK; gwerr_basic(_("value not in lambda scope"), NULL, NULL, env->name, exp_self(prim)->pos, 4242); - gwerr_secondary_from("declared here", v->from); + declared_here(v); gw_err("{-}hint:{0} try adding it to capture list"); env_set_error(env, true); return GW_ERROR; @@ -954,9 +954,7 @@ ANN static Type check_static(const Env env, const Exp e) { !GET_FLAG(t->info->func->def->base, abstract) || !is_static_call(env->gwion, e)) return t; env_err(env, e->pos, "making a static call to an abstract function"); - env->context->error = false; - gwerr_secondary_from("declared here", t->info->value->from); - env->context->error = true; + declared_here(t->info->value); return NULL; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index a32d1ee1..d2f2ab7d 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -300,8 +300,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { DECL_OO(const Type, parent, = cdef_parent(env, cdef)); if(GET_FLAG(cdef, global) && isa(parent, env->gwion->type[et_closure]) < 0 && !type_global(env, parent)) { gwerr_basic(_("parent type is not global"), NULL, NULL, env->name, cdef->base.ext ? cdef->base.ext->pos : cdef->base.pos, 0); - const Value v = parent->info->value; - gwerr_warn("declared here", NULL, NULL, v->from->filename, v->from->loc); + declared_here(parent->info->value); env_set_error(env, true); return NULL; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 56f2dc4f..c6ea9a05 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -285,7 +285,7 @@ ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const Func obase = overload->d.func_ref; if (GET_FLAG(obase->def->base, final) && (!env->class_def || (obase->value_ref->from->owner_class != env->class_def))) { env_err(env, f->base->pos, _("can't overload final function `{G}%s{0}`"), s_name(f->base->xid)); - env_warn(env, obase->def->base->pos, _("first declared here")); + declared_here(obase->value_ref); return GW_ERROR; } const m_bool base = tmpl_base(f->base->tmpl); -- 2.43.0