]> granicus.if.org Git - vim/commitdiff
patch 8.2.2443: Vim9: no compile time error for wrong str2float argument v8.2.2443
authorBram Moolenaar <Bram@vim.org>
Sun, 31 Jan 2021 19:48:58 +0000 (20:48 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 31 Jan 2021 19:48:58 +0000 (20:48 +0100)
Problem:    Vim9: no compile time error for wrong str2float argument.
Solution:   Check argument type. (closes #7759)

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

index 1fad082ac021834dd8b644cf9b8bf104da3307a7..f0a15f98ca1843be96476f024ee27036aeb32088 100644 (file)
@@ -435,6 +435,7 @@ arg_extend3(type_T *type, argcontext_T *context)
 /*
  * Lists of functions that check the argument types of a builtin function.
  */
+argcheck_T arg1_string[] = {arg_string};
 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};
@@ -1561,7 +1562,7 @@ static funcentry_T global_functions[] =
                        ret_list_number,    f_srand},
     {"state",          0, 1, FEARG_1,      NULL,
                        ret_string,         f_state},
-    {"str2float",      1, 1, FEARG_1,      NULL,
+    {"str2float",      1, 1, FEARG_1,      arg1_string,
                        ret_float,          FLOAT_FUNC(f_str2float)},
     {"str2list",       1, 2, FEARG_1,      NULL,
                        ret_list_number,    f_str2list},
index e7bec71c8e4ca1e3d312b1594e929422907a5e05..5fd510f579af32b4052be5cbb2de181300c2fb1b 100644 (file)
@@ -916,6 +916,18 @@ def Test_split()
   split('  aa  bb  ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
 enddef
 
+def Run_str2float()
+  if !has('float')
+    MissingFeature 'float'
+  endif
+    str2float("1.00")->assert_equal(1.00)
+    str2float("2e-2")->assert_equal(0.02)
+
+    CheckDefFailure(['echo str2float(123)'], 'E1013:')
+    CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
+  endif
+enddef
+
 def Test_str2nr()
   str2nr("1'000'000", 10, true)->assert_equal(1000000)
 
index d802f9c9110ffc99b8c5d4ea0c7d90f929ec90dc..b3d4feffd8e2289ffbe11224f961d49b971541fb 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2443,
 /**/
     2442,
 /**/