Mercurial > vim
diff src/vim9compile.c @ 22655:eabe2c1444ea v8.2.1876
patch 8.2.1876: Vim9: argument types are not checked at compile time
Commit: https://github.com/vim/vim/commit/94738d8fab09c5563e1512f1695e047c715ad274
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 21 14:25:07 2020 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 21 Oct 2020 14:30:04 +0200 |
parents | 5bd53bf63836 |
children | c6b17787a38f |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1460,8 +1460,7 @@ generate_BCALL(cctx_T *cctx, int func_id 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_id 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; }