]> Nishi Git Mirror - gwion.git/commitdiff
:art: Improve final function handling
authorJérémie Astor <fennecdjay@gmail.com>
Fri, 15 Apr 2022 12:28:20 +0000 (14:28 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Fri, 15 Apr 2022 12:28:20 +0000 (14:28 +0200)
src/parse/scan2.c
tests/error/file_scope_final_no_overload.gw [new file with mode: 0644]

index 1a8c663efde429d5775b0e23de5f0b11d9191c2a..0b795bc6ed5132dfa2b1363bcab205ec465aa25e 100644 (file)
@@ -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 (file)
index 0000000..da5b83b
--- /dev/null
@@ -0,0 +1,3 @@
+#! [contains] can't overload final function
+fun final void test() {}
+fun final void test(int i) {}