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

patch 9.0.1724: vim9class constructor argument type checking bug

Problem: vim9class constructor argument type checking bug
Solution: fix it

closes: #12816

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: h-east <h.east.727@gmail.com>
This commit is contained in:
h-east
2023-08-16 21:49:54 +09:00
committed by Christian Brabandt
parent 5a0dd71ed9
commit 2261c89a49
5 changed files with 108 additions and 7 deletions

View File

@@ -1780,6 +1780,7 @@ generate_CALL(
ufunc_T *ufunc,
class_T *cl,
int mi,
type_T *mtype, // method type
int pushed_argcount)
{
isn_T *isn;
@@ -1805,6 +1806,8 @@ generate_CALL(
{
int i;
compiletype_T compile_type;
int class_constructor = (mtype->tt_type == VAR_CLASS
&& STRNCMP(ufunc->uf_name, "new", 3) == 0);
for (i = 0; i < argcount; ++i)
{
@@ -1823,6 +1826,25 @@ generate_CALL(
if (ufunc->uf_arg_types == NULL)
continue;
expected = ufunc->uf_arg_types[i];
// When the method is a class constructor and the formal
// argument is an object member, the type check is performed on
// the object member type.
if (class_constructor && expected->tt_type == VAR_ANY)
{
class_T *clp = mtype->tt_class;
char_u *aname = ((char_u **)ufunc->uf_args.ga_data)[i];
for (int om = 0; om < clp->class_obj_member_count; ++om)
{
if (STRCMP(aname, clp->class_obj_members[om].ocm_name)
== 0)
{
expected = clp->class_obj_members[om].ocm_type;
break;
}
}
}
}
else if (ufunc->uf_va_type == NULL
|| ufunc->uf_va_type == &t_list_any)