]> granicus.if.org Git - vim/commitdiff
patch 8.2.3894: Vim9: no proper type check for first argument of call() v8.2.3894
authorBram Moolenaar <Bram@vim.org>
Sat, 25 Dec 2021 19:29:21 +0000 (19:29 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 25 Dec 2021 19:29:21 +0000 (19:29 +0000)
Problem:    Vim9: no proper type check for first argument of call().
Solution:   Add specific type check.

src/errors.h
src/evalfunc.c
src/proto/typval.pro
src/testdir/test_vim9_builtin.vim
src/typval.c
src/version.c

index e5b8cd218e26b059bd825d4ade89bf485f8843f4..e39e4044ada868b50a2d3bf74a20742aba441d1e 100644 (file)
@@ -852,3 +852,5 @@ EXTERN char e_cannot_use_script_variable_in_for_loop[]
        INIT(= N_("E1254: Cannot use script variable in for loop"));
 EXTERN char e_cmd_mapping_must_end_with_cr[]
        INIT(= N_("E1255: <Cmd> mapping must end with <CR>"));
+EXTERN char e_string_or_function_required_for_argument_nr[]
+       INIT(= N_("E1256: String or function required for argument %d"));
index 8f5205393817478f5e636aadb4692eafbb594d15..e4fa35b4efcf459263e2ad93ed3e814bd08ebfab 100644 (file)
@@ -2858,7 +2858,8 @@ f_call(typval_T *argvars, typval_T *rettv)
     dict_T     *selfdict = NULL;
 
     if (in_vim9script()
-           && (check_for_list_arg(argvars, 1) == FAIL
+           && (check_for_string_or_func_arg(argvars, 0) == FAIL
+               || check_for_list_arg(argvars, 1) == FAIL
                || check_for_opt_dict_arg(argvars, 2) == FAIL))
        return;
 
index f5804a3179d0fdc4f9f6ea56d5dcdd8cc3ba1d5d..f04bf1539ad872d6afc5d9c88cbb6eded60c1d2e 100644 (file)
@@ -40,6 +40,7 @@ int check_for_string_or_dict_arg(typval_T *args, int idx);
 int check_for_string_or_number_or_list_arg(typval_T *args, int idx);
 int check_for_opt_string_or_number_or_list_arg(typval_T *args, int idx);
 int check_for_string_or_list_or_dict_arg(typval_T *args, int idx);
+int check_for_string_or_func_arg(typval_T *args, int idx);
 int check_for_list_or_blob_arg(typval_T *args, int idx);
 int check_for_list_or_dict_arg(typval_T *args, int idx);
 int check_for_list_or_dict_or_blob_arg(typval_T *args, int idx);
index 298a3be5228f22656266983eaab5cb98da4595dc..1bdb12b039c50cbec92341199759223f36079985 100644 (file)
@@ -402,6 +402,9 @@ def Test_call_call()
   var l = [3, 2, 1]
   call('reverse', [l])
   l->assert_equal([1, 2, 3])
+
+  CheckDefExecAndScriptFailure(['call(123, [2])'], 'E1256: String or function required for argument 1')
+  CheckDefExecAndScriptFailure(['call(true, [2])'], 'E1256: String or function required for argument 1')
   CheckDefAndScriptFailure(['call("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
   CheckDefAndScriptFailure(['call("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
 enddef
index 358e04e67e57c1e5c3f998d49d2f09164e1cca79..2f773b602ee67756a14b5bdd03fb55b1fbec4278 100644 (file)
@@ -756,6 +756,23 @@ check_for_string_or_list_or_dict_arg(typval_T *args, int idx)
     return OK;
 }
 
+/*
+ * Give an error and return FAIL unless "args[idx]" is a string
+ * or a function reference.
+ */
+    int
+check_for_string_or_func_arg(typval_T *args, int idx)
+{
+    if (args[idx].v_type != VAR_PARTIAL
+           && args[idx].v_type != VAR_FUNC
+           && args[idx].v_type != VAR_STRING)
+    {
+       semsg(_(e_string_or_function_required_for_argument_nr), idx + 1);
+       return FAIL;
+    }
+    return OK;
+}
+
 /*
  * Give an error and return FAIL unless "args[idx]" is a list or a blob.
  */
index 423ec6ecc195645ddb6002a14af359485d72d2cb..c4e4ad081411b65dcf02b02765b167305e148cbb 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3894,
 /**/
     3893,
 /**/