diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-17 19:11:07 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-17 19:11:07 +0200 |
commit | a9a7c0c602b231dc37c4b0f62ade0421c84fca03 (patch) | |
tree | a7e6e2dcad98c9dd2244cf9c368360b71abf61a6 /src/typval.c | |
parent | 20c370d9f2ee89cb854054edf71f5004f6efff77 (diff) | |
download | vim-git-a9a7c0c602b231dc37c4b0f62ade0421c84fca03.tar.gz |
patch 8.2.3173: Vim9: argument types are not checked at compile timev8.2.3173
Problem: Vim9: argument types are not checked at compile time.
Solution: Add more type checks. (Yegappan Lakshmanan, closes #8581)
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/typval.c b/src/typval.c index 6e0b528e7..03891c806 100644 --- a/src/typval.c +++ b/src/typval.c @@ -352,7 +352,7 @@ tv_get_float(typval_T *varp) #endif /* - * Give an error and return FAIL unless "tv" is a string. + * Give an error and return FAIL unless "args[idx]" is a string. */ int check_for_string_arg(typval_T *args, int idx) @@ -385,7 +385,7 @@ check_for_nonempty_string_arg(typval_T *args, int idx) } /* - * Give an error and return FAIL unless "tv" is a number. + * Give an error and return FAIL unless "args[idx]" is a number. */ int check_for_number_arg(typval_T *args, int idx) @@ -402,7 +402,44 @@ check_for_number_arg(typval_T *args, int idx) } /* - * Give an error and return FAIL unless "tv" is a dict. + * Give an error and return FAIL unless "args[idx]" is a bool. + */ + int +check_for_bool_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_BOOL + && !(args[idx].v_type == VAR_NUMBER + && (args[idx].vval.v_number == 0 + || args[idx].vval.v_number == 1))) + { + if (idx >= 0) + semsg(_(e_bool_required_for_argument_nr), idx + 1); + else + emsg(_(e_boolreq)); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a list. + */ + int +check_for_list_arg(typval_T *args, int idx) +{ + if (args[idx].v_type != VAR_LIST) + { + if (idx >= 0) + semsg(_(e_list_required_for_argument_nr), idx + 1); + else + emsg(_(e_listreq)); + return FAIL; + } + return OK; +} + +/* + * Give an error and return FAIL unless "args[idx]" is a dict. */ int check_for_dict_arg(typval_T *args, int idx) |