Patch 8.2.3023
Problem:    Vim9: arguments for execute() not checked at compile time.
Solution:   Add a function to check the argument types.
Files:      src/evalfunc.c, src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.3022/src/evalfunc.c      2021-06-20 14:01:25.984924607 +0200
--- src/evalfunc.c      2021-06-20 14:40:31.988102929 +0200
***************
*** 302,307 ****
--- 302,328 ----
  }
  
  /*
+  * Check "type" is a string or a list of strings.
+  */
+     static int
+ arg_string_or_list(type_T *type, argcontext_T *context)
+ {
+     if (type->tt_type == VAR_ANY || type->tt_type == VAR_STRING)
+       return OK;
+     if (type->tt_type != VAR_LIST)
+     {
+       arg_type_mismatch(&t_string, type, context->arg_idx + 1);
+       return FAIL;
+     }
+     if (type->tt_member->tt_type == VAR_ANY
+                   || type->tt_member->tt_type == VAR_STRING)
+       return OK;
+ 
+     arg_type_mismatch(&t_list_string, type, context->arg_idx + 1);
+     return FAIL;
+ }
+ 
+ /*
   * Check "type" is a list or a dict.
   */
      static int
***************
*** 385,390 ****
--- 406,412 ----
  argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool};
  argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
  argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
+ argcheck_T arg2_execute[] = {arg_string_or_list, arg_string};
  argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3};
  argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, 
arg_extend3};
  argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number};
***************
*** 870,876 ****
                        ret_number_bool,    f_eventhandler},
      {"executable",    1, 1, FEARG_1,      NULL,
                        ret_number,         f_executable},
!     {"execute",               1, 2, FEARG_1,      NULL,
                        ret_string,         f_execute},
      {"exepath",               1, 1, FEARG_1,      NULL,
                        ret_string,         f_exepath},
--- 892,898 ----
                        ret_number_bool,    f_eventhandler},
      {"executable",    1, 1, FEARG_1,      NULL,
                        ret_number,         f_executable},
!     {"execute",               1, 2, FEARG_1,      arg2_execute,
                        ret_string,         f_execute},
      {"exepath",               1, 1, FEARG_1,      NULL,
                        ret_string,         f_exepath},
*** ../vim-8.2.3022/src/testdir/test_vim9_builtin.vim   2021-06-05 
20:51:34.737122348 +0200
--- src/testdir/test_vim9_builtin.vim   2021-06-20 14:37:14.536771968 +0200
***************
*** 324,329 ****
--- 324,341 ----
    CheckDefExecFailure(['echo executable(true)'], 'E1174:')
  enddef
  
+ def Test_execute()
+   var res = execute("echo 'hello'")
+   assert_equal("\nhello", res)
+   res = execute(["echo 'here'", "echo 'there'"])
+   assert_equal("\nhere\nthere", res)
+ 
+   CheckDefFailure(['echo execute(123)'], 'E1013: Argument 1: type mismatch, 
expected string but got number')
+   CheckDefFailure(['echo execute([123])'], 'E1013: Argument 1: type mismatch, 
expected list<string> but got list<number>')
+   CheckDefExecFailure(['echo execute(["xx", 123])'], 'E492')
+   CheckDefFailure(['echo execute("xx", 123)'], 'E1013: Argument 2: type 
mismatch, expected string but got number')
+ enddef
+ 
  def Test_exepath()
    CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
    CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
*** ../vim-8.2.3022/src/version.c       2021-06-20 14:01:25.988924596 +0200
--- src/version.c       2021-06-20 14:29:11.630424630 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3023,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
25. You believe nothing looks sexier than a man in boxer shorts illuminated
    only by a 17" inch svga monitor.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202106201241.15KCfUHo325971%40masaka.moolenaar.net.

Raspunde prin e-mail lui