forked from aniani/vim
patch 8.2.1876: Vim9: argument types are not checked at compile time
Problem: Vim9: argument types for builtin functions are not checked at compile time. Solution: Add an argument type checking mechanism. Implement type checks for one function.
This commit is contained in:
@@ -1460,8 +1460,7 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
|
||||
isn_T *isn;
|
||||
garray_T *stack = &cctx->ctx_type_stack;
|
||||
int argoff;
|
||||
type_T *argtypes[MAX_FUNC_ARGS];
|
||||
int i;
|
||||
type_T **argtypes;
|
||||
|
||||
RETURN_OK_IF_SKIP(cctx);
|
||||
argoff = check_internal_func(func_idx, argcount);
|
||||
@@ -1476,20 +1475,24 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
|
||||
isn->isn_arg.shuffle.shfl_up = argoff - 1;
|
||||
}
|
||||
|
||||
// Check the types of the arguments.
|
||||
argtypes = ((type_T **)stack->ga_data) + stack->ga_len - argcount;
|
||||
if (argcount > 0 && internal_func_check_arg_types(
|
||||
*argtypes, func_idx, argcount) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL)
|
||||
return FAIL;
|
||||
isn->isn_arg.bfunc.cbf_idx = func_idx;
|
||||
isn->isn_arg.bfunc.cbf_argcount = argcount;
|
||||
|
||||
for (i = 0; i < argcount; ++i)
|
||||
argtypes[i] = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
|
||||
|
||||
stack->ga_len -= argcount; // drop the arguments
|
||||
// Drop the argument types and push the return type.
|
||||
stack->ga_len -= argcount;
|
||||
if (ga_grow(stack, 1) == FAIL)
|
||||
return FAIL;
|
||||
((type_T **)stack->ga_data)[stack->ga_len] =
|
||||
internal_func_ret_type(func_idx, argcount, argtypes);
|
||||
++stack->ga_len; // add return value
|
||||
++stack->ga_len;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user