diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-25 23:39:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 23:39:15 +0800 |
commit | 7e0d66801297677ecbb6b35d0c9139e672920be4 (patch) | |
tree | 74a2df0aa302d7d0b6b1084b4f54a365c0b0205b /src/nvim/eval/typval.c | |
parent | ac9f8669a8e4bd0cf13468d316d1746be65d3cdc (diff) | |
download | rneovim-7e0d66801297677ecbb6b35d0c9139e672920be4.tar.gz rneovim-7e0d66801297677ecbb6b35d0c9139e672920be4.tar.bz2 rneovim-7e0d66801297677ecbb6b35d0c9139e672920be4.zip |
vim-patch:partial:9.0.0359: error message for wrong argument type is not specific (#23315)
Problem: Error message for wrong argument type is not specific.
Solution: Include more information in the error. (Yegappan Lakshmanan,
closes vim/vim#11037)
https://github.com/vim/vim/commit/8deb2b30c77035bb682ccf80b781455ac1d6038b
Skip reduce() and deepcopy() changes because of missing patches.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index e4b809d98d..6556e274ab 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -50,6 +50,8 @@ static const char e_number_required_for_argument_nr[] = N_("E1210: Number required for argument %d"); static const char e_list_required_for_argument_nr[] = N_("E1211: List required for argument %d"); +static const char e_bool_required_for_argument_nr[] + = N_("E1212: Bool required for argument %d"); static const char e_string_or_list_required_for_argument_nr[] = N_("E1222: String or List required for argument %d"); static const char e_list_or_blob_required_for_argument_nr[] @@ -4000,6 +4002,14 @@ int tv_check_for_nonempty_string_arg(const typval_T *const args, const int idx) return OK; } +/// Check for an optional string argument at "idx" +int tv_check_for_opt_string_arg(const typval_T *const args, const int idx) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE +{ + return (args[idx].v_type == VAR_UNKNOWN + || tv_check_for_string_arg(args, idx) != FAIL) ? OK : FAIL; +} + /// Give an error and return FAIL unless "args[idx]" is a number. int tv_check_for_number_arg(const typval_T *const args, const int idx) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE @@ -4019,6 +4029,31 @@ int tv_check_for_opt_number_arg(const typval_T *const args, const int idx) || tv_check_for_number_arg(args, idx) != FAIL) ? OK : FAIL; } +/// Give an error and return FAIL unless "args[idx]" is a bool. +int tv_check_for_bool_arg(const typval_T *const args, const int idx) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE +{ + 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))) { + semsg(_(e_bool_required_for_argument_nr), idx + 1); + return FAIL; + } + return OK; +} + +/// Check for an optional bool argument at "idx". +/// Return FAIL if the type is wrong. +int tv_check_for_opt_bool_arg(const typval_T *const args, const int idx) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE +{ + if (args[idx].v_type == VAR_UNKNOWN) { + return OK; + } + return tv_check_for_bool_arg(args, idx); +} + /// Give an error and return FAIL unless "args[idx]" is a blob. int tv_check_for_blob_arg(const typval_T *const args, const int idx) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE |