]> granicus.if.org Git - vim/commitdiff
patch 8.2.1136: Vim9: return type of argv() is always any v8.2.1136
authorBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 15:04:13 +0000 (17:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 15:04:13 +0000 (17:04 +0200)
Problem:    Vim9: return type of argv() is always any.
Solution:   Use list<string> if there is no argument.

src/evalfunc.c
src/testdir/test_vim9_func.vim
src/version.c

index c3eaef2ea574f915d2f15a6cd02ba7f9960c934d..5215befb5a661cb55f1e9751699d80b3b46d2842 100644 (file)
@@ -371,6 +371,17 @@ ret_list_or_dict_1(int argcount, type_T **argtypes UNUSED)
     return &t_list_dict_any;
 }
 
+    static type_T *
+ret_argv(int argcount, type_T **argtypes UNUSED)
+{
+    // argv() returns list of strings
+    if (argcount == 0)
+       return &t_list_string;
+
+    // argv(0) returns a string, but argv(-1] returns a list
+    return &t_any;
+}
+
 static type_T *ret_f_function(int argcount, type_T **argtypes);
 
 /*
@@ -448,7 +459,7 @@ static funcentry_T global_functions[] =
     {"argc",           0, 1, 0,          ret_number,   f_argc},
     {"argidx",         0, 0, 0,          ret_number,   f_argidx},
     {"arglistid",      0, 2, 0,          ret_number,   f_arglistid},
-    {"argv",           0, 2, 0,          ret_any,      f_argv},
+    {"argv",           0, 2, 0,          ret_argv,     f_argv},
     {"asin",           1, 1, FEARG_1,    ret_float,    FLOAT_FUNC(f_asin)},
     {"assert_beeps",   1, 2, FEARG_1,    ret_number,   f_assert_beeps},
     {"assert_equal",   2, 3, FEARG_2,    ret_number,   f_assert_equal},
index cc938a50ef79bb99ebacd158b32985588bb835e3..c3236fff15f0c5921ebddecc2c9a25b2427a6430 100644 (file)
@@ -610,6 +610,15 @@ def Test_repeat_return_type()
   assert_equal(6, res)
 enddef
 
+def Test_argv_return_type()
+  next fileone filetwo
+  let res = ''
+  for name in argv()
+    res ..= name
+  endfor
+  assert_equal('fileonefiletwo', res)
+enddef
+
 def Test_func_type_part()
   let RefVoid: func: void
   RefVoid = FuncNoArgNoRet
index 82e4c6ddcbd91fb241aa4c8deb685243995cca3c..23a94348f8f0e390fbd110c682af98152c802baf 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1136,
 /**/
     1135,
 /**/