0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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>
This commit is contained in:
Ernie Rael
2024-08-13 23:27:22 +02:00
committed by Christian Brabandt
parent d33afe12c6
commit 58c9579430
7 changed files with 171 additions and 15 deletions

View File

@@ -349,6 +349,11 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
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 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
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 @@ compile_builtin_method_call(cctx_T *cctx, class_builtin_T builtin_method)
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 @@ compile_call(
{
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 @@ compile_call(
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 @@ compile_call(
// 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;
}