From: Jérémie Astor Date: Fri, 15 Apr 2022 12:28:20 +0000 (+0200) Subject: :art: Improve final function handling X-Git-Tag: nightly~311 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ff6a494b55c76301e19f9dc2d70fd12ef8961c1c;p=gwion.git :art: Improve final function handling --- diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 1a8c663e..0b795bc6 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -311,8 +311,11 @@ ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, } const Func obase = !fptr ? overload->d.func_ref : _class_base(overload->type)->info->func; - if (GET_FLAG(obase->def->base, final) && obase->value_ref->from->owner_class != env->class_def) - ERR_B(f->base->pos, _("can't overload final function %s"), overload->name) + 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")); + return GW_ERROR; + } const m_bool base = tmpl_base(f->base->tmpl); const m_bool tmpl = fflag(obase, fflag_tmpl); if ((!tmpl && base) || (tmpl && !base && !f->base->tmpl)) diff --git a/tests/error/file_scope_final_no_overload.gw b/tests/error/file_scope_final_no_overload.gw new file mode 100644 index 00000000..da5b83b7 --- /dev/null +++ b/tests/error/file_scope_final_no_overload.gw @@ -0,0 +1,3 @@ +#! [contains] can't overload final function +fun final void test() {} +fun final void test(int i) {}