patch 9.1.0673: Vim9: too recursive func calls when calling super-class method
Problem: Vim9: too recursive func calls when calling super-class method
with non-overriden super-call methods. (Aliaksei Budavei)
Solution: use interface method, when super is to be used (Ernie Rael)
When compiling "super.Func()" force class context to class that defines
function that is doing "super.Func()".
ISN_METHODCALL arg "cmf_is_super" for specific ufunc.
fixes: #15448
fixes: #15463 (2) super.method may not execute in context of defining
class
closes: #15477
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/vim9expr.c b/src/vim9expr.c
index c2428f4..cfdea7b 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -349,6 +349,11 @@
else
{
// type->tt_type == VAR_OBJECT: method call
+ // When compiling Func and doing "super.SomeFunc()", must be in the
+ // class context that defines Func.
+ if (is_super)
+ cl = cctx->ctx_ufunc->uf_defclass;
+
function_count = cl->class_obj_method_count;
child_count = cl->class_obj_method_count_child;
functions = cl->class_obj_methods;
@@ -419,8 +424,8 @@
return generate_PCALL(cctx, argcount, name, ocm->ocm_type, TRUE);
if (type->tt_type == VAR_OBJECT
&& (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED)))
- return generate_CALL(cctx, ufunc, cl, fi, argcount);
- return generate_CALL(cctx, ufunc, NULL, 0, argcount);
+ return generate_CALL(cctx, ufunc, cl, fi, argcount, is_super);
+ return generate_CALL(cctx, ufunc, NULL, 0, argcount, FALSE);
}
if (type->tt_type == VAR_OBJECT)
@@ -1035,7 +1040,7 @@
ufunc_T *uf = class_get_builtin_method(type->tt_class, builtin_method,
&method_idx);
if (uf != NULL)
- res = generate_CALL(cctx, uf, type->tt_class, method_idx, 0);
+ res = generate_CALL(cctx, uf, type->tt_class, method_idx, 0, FALSE);
}
return res;
@@ -1238,7 +1243,7 @@
{
if (!func_is_global(ufunc))
{
- res = generate_CALL(cctx, ufunc, NULL, 0, argcount);
+ res = generate_CALL(cctx, ufunc, NULL, 0, argcount, FALSE);
goto theend;
}
if (!has_g_namespace
@@ -1257,7 +1262,7 @@
if (cctx->ctx_ufunc->uf_defclass == cl)
{
res = generate_CALL(cctx, cl->class_class_functions[mi], NULL,
- 0, argcount);
+ 0, argcount, FALSE);
}
else
{
@@ -1285,7 +1290,7 @@
// If we can find a global function by name generate the right call.
if (ufunc != NULL)
{
- res = generate_CALL(cctx, ufunc, NULL, 0, argcount);
+ res = generate_CALL(cctx, ufunc, NULL, 0, argcount, FALSE);
goto theend;
}