Skip to content

Commit 80ad3e2

Browse files
committed
patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Problem: Vim9: no compile time error for wrong str2float argument. Solution: Check argument type. (closes #7759)
1 parent f272ae1 commit 80ad3e2

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/evalfunc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ arg_extend3(type_T *type, argcontext_T *context)
435435
/*
436436
* Lists of functions that check the argument types of a builtin function.
437437
*/
438+
argcheck_T arg1_string[] = {arg_string};
438439
argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool};
439440
argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
440441
argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
@@ -1561,7 +1562,7 @@ static funcentry_T global_functions[] =
15611562
ret_list_number, f_srand},
15621563
{"state", 0, 1, FEARG_1, NULL,
15631564
ret_string, f_state},
1564-
{"str2float", 1, 1, FEARG_1, NULL,
1565+
{"str2float", 1, 1, FEARG_1, arg1_string,
15651566
ret_float, FLOAT_FUNC(f_str2float)},
15661567
{"str2list", 1, 2, FEARG_1, NULL,
15671568
ret_list_number, f_str2list},

src/testdir/test_vim9_builtin.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,18 @@ def Test_split()
916916
split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
917917
enddef
918918

919+
def Run_str2float()
920+
if !has('float')
921+
MissingFeature 'float'
922+
endif
923+
str2float("1.00")->assert_equal(1.00)
924+
str2float("2e-2")->assert_equal(0.02)
925+
926+
CheckDefFailure(['echo str2float(123)'], 'E1013:')
927+
CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
928+
endif
929+
enddef
930+
919931
def Test_str2nr()
920932
str2nr("1'000'000", 10, true)->assert_equal(1000000)
921933

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2443,
753755
/**/
754756
2442,
755757
/**/

0 commit comments

Comments
 (0)