summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-21 14:25:07 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-21 14:25:07 +0200
commit94738d8fab09c5563e1512f1695e047c715ad274 (patch)
treed3d53894638221c11e7e721d7f9396e131b0a4e1 /src/vim9compile.c
parent3da855c8e28140d9f02b1572e445f8d4f977cf64 (diff)
downloadvim-git-94738d8fab09c5563e1512f1695e047c715ad274.tar.gz
patch 8.2.1876: Vim9: argument types are not checked at compile timev8.2.1876
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.
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index cd5e45bc6..289b941bf 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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;
}