]> granicus.if.org Git - vim/commitdiff
patch 8.2.1624: Vim9: cannot pass "true" to split(), str2nr() and strchars() v8.2.1624
authorBram Moolenaar <Bram@vim.org>
Sun, 6 Sep 2020 14:09:04 +0000 (16:09 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 Sep 2020 14:09:04 +0000 (16:09 +0200)
Problem:    Vim9: cannot pass "true" to split(), str2nr() and strchars().
Solution:   Use tv_get_bool_chk(). (closes #6884, closes #6885, closes #6886)

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

index 810769ae226e9b9f777916e24f1a724d0b06b425..e7683fc3dc2d5d8b13934b6dde13ef10b574bb68 100644 (file)
@@ -7884,7 +7884,7 @@ f_split(typval_T *argvars, typval_T *rettv)
        if (pat == NULL)
            typeerr = TRUE;
        if (argvars[2].v_type != VAR_UNKNOWN)
-           keepempty = (int)tv_get_number_chk(&argvars[2], &typeerr);
+           keepempty = (int)tv_get_bool_chk(&argvars[2], &typeerr);
     }
     if (pat == NULL || *pat == NUL)
        pat = (char_u *)"[\\x01- ]\\+";
@@ -8030,7 +8030,7 @@ f_str2nr(typval_T *argvars, typval_T *rettv)
            emsg(_(e_invarg));
            return;
        }
-       if (argvars[2].v_type != VAR_UNKNOWN && tv_get_number(&argvars[2]))
+       if (argvars[2].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[2]))
            what |= STR2NR_QUOTE;
     }
 
@@ -8155,12 +8155,12 @@ f_strlen(typval_T *argvars, typval_T *rettv)
 f_strchars(typval_T *argvars, typval_T *rettv)
 {
     char_u             *s = tv_get_string(&argvars[0]);
-    int                        skipcc = 0;
+    int                        skipcc = FALSE;
     varnumber_T                len = 0;
     int                        (*func_mb_ptr2char_adv)(char_u **pp);
 
     if (argvars[1].v_type != VAR_UNKNOWN)
-       skipcc = (int)tv_get_number_chk(&argvars[1], NULL);
+       skipcc = (int)tv_get_bool(&argvars[1]);
     if (skipcc < 0 || skipcc > 1)
        emsg(_(e_invarg));
     else
index a277767735d29d6fc2a150e48df8b85afd6a8d70..e31551714f5212b4d2b4eb807946a473eaa4f693 100644 (file)
@@ -1636,6 +1636,18 @@ def Test_spellsuggest()
   endif
 enddef
 
+def Test_split()
+  split('  aa  bb  ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
+enddef
+
+def Test_str2nr()
+  str2nr("1'000'000", 10, true)->assert_equal(1000000)
+enddef
+
+def Test_strchars()
+  strchars("A\u20dd", true)->assert_equal(1)
+enddef
+
 def Test_synID()
   new
   setline(1, "text")
index ae775d9b8d562abbba66a513a061fcd1b78b75f9..6a6d9948804ffc239e456b0fe2c1e1c1cd4b6f07 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1624,
 /**/
     1623,
 /**/