aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-27 20:59:43 +0800
committerGitHub <noreply@github.com>2022-07-27 20:59:43 +0800
commitf57432af4db184912af7c107f2bba23b5c37473a (patch)
tree06bac57c9df8ef23ca6b239002c0561a57cd11b2
parente0f32abb1c691793abdc3e28c5054d8f1d4b99c7 (diff)
downloadrneovim-f57432af4db184912af7c107f2bba23b5c37473a.tar.gz
rneovim-f57432af4db184912af7c107f2bba23b5c37473a.tar.bz2
rneovim-f57432af4db184912af7c107f2bba23b5c37473a.zip
vim-patch:9.0.0090: no error when assigning bool to a string option (#19539)
Problem: No error when assigning bool to a string option with setwinvar(). Solution: Give an error (closes vim/vim#10766) https://github.com/vim/vim/commit/28f84e17b068daca2635692d279930dcb7a150d0
-rw-r--r--src/nvim/eval/vars.c4
-rw-r--r--src/nvim/option.c8
-rw-r--r--test/functional/vimscript/buf_functions_spec.lua4
3 files changed, 16 insertions, 0 deletions
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 190cc62d85..1aecb40e0b 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -1617,6 +1617,10 @@ static void set_option_from_tv(const char *varname, typval_T *varp)
char nbuf[NUMBUFLEN];
if (varp->v_type == VAR_BOOL) {
+ if (is_string_option(varname)) {
+ emsg(_(e_stringreq));
+ return;
+ }
numval = (long)varp->vval.v_number;
strval = "0"; // avoid using "false"
} else {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index ea4c7080b7..7edc2e55f5 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -5301,6 +5301,14 @@ char *set_option_value(const char *const name, const long number, const char *co
return NULL;
}
+/// Return true if "name" is a string option.
+/// Returns false if option "name" does not exist.
+bool is_string_option(const char *name)
+{
+ int idx = findoption(name);
+ return idx >= 0 && (options[idx].flags & P_STRING);
+}
+
// Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
// When "has_lt" is true there is a '<' before "*arg_arg".
// Returns 0 when the key is not recognized.
diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua
index e957e5f5af..b521620320 100644
--- a/test/functional/vimscript/buf_functions_spec.lua
+++ b/test/functional/vimscript/buf_functions_spec.lua
@@ -303,4 +303,8 @@ describe('setbufvar() function', function()
pcall_err(funcs.setbufvar, 1, 'changedtick', true))
eq(2, funcs.getbufvar(1, 'changedtick'))
end)
+ it('throws error when setting a string option to a boolean value vim-patch:9.0.0090', function()
+ eq('Vim:E928: String required',
+ pcall_err(funcs.setbufvar, '', '&errorformat', true))
+ end)
end)