From ff6a494b55c76301e19f9dc2d70fd12ef8961c1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Fri, 15 Apr 2022 14:28:20 +0200 Subject: [PATCH] :art: Improve final function handling --- src/parse/scan2.c | 7 +++++-- tests/error/file_scope_final_no_overload.gw | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/error/file_scope_final_no_overload.gw 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) {} -- 2.43.0