diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-06-20 14:41:01 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-20 14:41:01 +0200 |
commit | ca81f0e834640cf3465b3b742e60c12e8a0956f2 (patch) | |
tree | 7c2b244badcd480fb6e699a72e4e72f784feacb2 /src | |
parent | f573c6e1ed58d46d694c802eaf5ae3662a952744 (diff) | |
download | vim-git-ca81f0e834640cf3465b3b742e60c12e8a0956f2.tar.gz |
patch 8.2.3023: Vim9: arguments for execute() not checked at compile timev8.2.3023
Problem: Vim9: arguments for execute() not checked at compile time.
Solution: Add a function to check the argument types.
Diffstat (limited to 'src')
-rw-r--r-- | src/evalfunc.c | 24 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 9267117da..fdcc00fe8 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -302,6 +302,27 @@ arg_list_or_blob(type_T *type, argcontext_T *context) } /* + * 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,6 +406,7 @@ 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}; +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,7 +892,7 @@ static funcentry_T global_functions[] = ret_number_bool, f_eventhandler}, {"executable", 1, 1, FEARG_1, NULL, ret_number, f_executable}, - {"execute", 1, 2, FEARG_1, NULL, + {"execute", 1, 2, FEARG_1, arg2_execute, ret_string, f_execute}, {"exepath", 1, 1, FEARG_1, NULL, ret_string, f_exepath}, diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index b98c840ce..d8fd079bf 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -324,6 +324,18 @@ def Test_executable() 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:') diff --git a/src/version.c b/src/version.c index 646481612..d341ecd41 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3023, +/**/ 3022, /**/ 3021, |