mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2306: Vim9: when using function reference type is not checked
Problem: Vim9: when using function reference type is not checked. Solution: When using a function reference lookup the type and check the argument types. (issue #7629)
This commit is contained in:
@@ -527,6 +527,46 @@ check_arg_type(type_T *expected, type_T *actual, int argidx)
|
||||
return check_type(expected, actual, TRUE, argidx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the arguments of "type" match "argvars[argcount]".
|
||||
* Return OK/FAIL.
|
||||
*/
|
||||
int
|
||||
check_argument_types(type_T *type, typval_T *argvars, int argcount, char_u *name)
|
||||
{
|
||||
int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
|
||||
int i;
|
||||
|
||||
if (type->tt_type != VAR_FUNC && type->tt_type != VAR_PARTIAL)
|
||||
return OK; // just in case
|
||||
if (argcount < type->tt_min_argcount - varargs)
|
||||
{
|
||||
semsg(_(e_toofewarg), name);
|
||||
return FAIL;
|
||||
}
|
||||
if (!varargs && type->tt_argcount >= 0 && argcount > type->tt_argcount)
|
||||
{
|
||||
semsg(_(e_toomanyarg), name);
|
||||
return FAIL;
|
||||
}
|
||||
if (type->tt_args == NULL)
|
||||
return OK; // cannot check
|
||||
|
||||
|
||||
for (i = 0; i < argcount; ++i)
|
||||
{
|
||||
type_T *expected;
|
||||
|
||||
if (varargs && i >= type->tt_argcount - 1)
|
||||
expected = type->tt_args[type->tt_argcount - 1]->tt_member;
|
||||
else
|
||||
expected = type->tt_args[i];
|
||||
if (check_typval_type(expected, &argvars[i], i + 1) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip over a type definition and return a pointer to just after it.
|
||||
* When "optional" is TRUE then a leading "?" is accepted.
|
||||
|
Reference in New Issue
Block a user