From: Jérémie Astor Date: Sun, 12 Jul 2020 17:16:19 +0000 (+0200) Subject: :art: Improve Function shadowing X-Git-Tag: nightly~1444 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e4d5c1d053c7da0474abd242bdbceaa52e6376da;p=gwion.git :art: Improve Function shadowing --- diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 730e9811..c4e6e919 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -502,9 +502,20 @@ ANN m_bool scan1_fdef(const Env env, const Func_Def fdef) { return GW_OK; } +ANN static inline m_bool scan1_fdef_defined(const Env env, const Func_Def fdef) { + const Value v = nspc_lookup_value1(env->curr, fdef->base->xid); + if(!v) + return GW_OK; + if(isa(actual_type(env->gwion, v->type), env->gwion->type[et_function]) > 0) + return GW_OK; + ERR_B(fdef->pos, _("function '%s' has already been defined in the same scope..."), + s_name(fdef->base->xid)) +} + ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { if(fdef->base->td) CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td))) + CHECK_BB(scan1_fdef_defined(env, fdef)) if(tmpl_base(fdef->base->tmpl)) return scan1_fdef_base_tmpl(env, fdef->base); struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func;