From 3ea45a2caf23ac1c335d04c0a3b2b2aa254d3d96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Jul 2022 16:56:11 +0800 Subject: vim-patch:8.2.1469: Vim9: cannot assign string to string option Problem: Vim9: cannot assign string to string option. Solution: Change checks for option value. (closes vim/vim#6720) https://github.com/vim/vim/commit/0aae4809fd52b445531766411a9c963dc6274a04 --- src/nvim/eval/vars.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index e56ccef02b..edc112109a 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -619,24 +619,32 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo && vim_strchr(endchars, *skipwhite(p)) == NULL)) { emsg(_(e_letunexp)); } else { + varnumber_T n = 0; int opt_type; long numval; char *stringval = NULL; const char *s = NULL; + bool failed = false; const char c1 = *p; *p = NUL; - varnumber_T n = tv_get_number(tv); + opt_type = get_option_value(arg, &numval, &stringval, opt_flags); + if (opt_type == 1 || opt_type == -1) { + // number, possibly hidden + n = (long)tv_get_number(tv); + } + + // Avoid setting a string option to the text "v:false" or similar. if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) { - s = tv_get_string_chk(tv); // != NULL if number or string. + s = tv_get_string_chk(tv); } - if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value(arg, &numval, &stringval, opt_flags); + + if (op != NULL && *op != '=') { if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { semsg(_(e_letwrong), op); - s = NULL; // don't set the value + failed = true; // don't set the value } else { if (opt_type == 1) { // number switch (*op) { @@ -651,7 +659,8 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo case '%': n = num_modulus(numval, n); break; } - } else if (opt_type == 0 && stringval != NULL) { // string + } else if (opt_type == 0 && stringval != NULL && s != NULL) { + // string char *const oldstringval = stringval; stringval = (char *)concat_str((const char_u *)stringval, (const char_u *)s); @@ -660,10 +669,14 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } } } - if (s != NULL || tv->v_type == VAR_BOOL - || tv->v_type == VAR_SPECIAL) { - set_option_value((const char *)arg, n, s, opt_flags); - arg_end = p; + + if (!failed) { + if (opt_type != 0 || s != NULL) { + set_option_value(arg, n, s, opt_flags); + arg_end = p; + } else { + emsg(_(e_stringreq)); + } } *p = c1; xfree(stringval); -- cgit From 2241fd3211012e5eba3479d64e190f206c12087e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Jul 2022 17:37:06 +0800 Subject: vim-patch:8.2.2254: Vim9: bool option type is number Problem: Vim9: bool option type is number. Solution: Have get_option_value() return a different value for bool and number options. (closes vim/vim#7583) https://github.com/vim/vim/commit/dd1f426bd617ac6a775f2e7795ff0b159e3fa315 --- src/nvim/eval/vars.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index edc112109a..091e3f87c4 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -620,7 +620,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo emsg(_(e_letunexp)); } else { varnumber_T n = 0; - int opt_type; + getoption_T opt_type; long numval; char *stringval = NULL; const char *s = NULL; @@ -630,7 +630,10 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo *p = NUL; opt_type = get_option_value(arg, &numval, &stringval, opt_flags); - if (opt_type == 1 || opt_type == -1) { + if (opt_type == gov_bool + || opt_type == gov_number + || opt_type == gov_hidden_bool + || opt_type == gov_hidden_number) { // number, possibly hidden n = (long)tv_get_number(tv); } @@ -641,12 +644,13 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } if (op != NULL && *op != '=') { - if ((opt_type == 1 && *op == '.') - || (opt_type == 0 && *op != '.')) { + if (((opt_type == gov_bool || opt_type == gov_number) && *op == '.') + || (opt_type == gov_string && *op != '.')) { semsg(_(e_letwrong), op); failed = true; // don't set the value } else { - if (opt_type == 1) { // number + // number or bool + if (opt_type == gov_number || opt_type == gov_bool) { switch (*op) { case '+': n = numval + n; break; @@ -659,7 +663,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo case '%': n = num_modulus(numval, n); break; } - } else if (opt_type == 0 && stringval != NULL && s != NULL) { + } else if (opt_type == gov_string && stringval != NULL && s != NULL) { // string char *const oldstringval = stringval; stringval = (char *)concat_str((const char_u *)stringval, @@ -671,7 +675,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo } if (!failed) { - if (opt_type != 0 || s != NULL) { + if (opt_type != gov_string || s != NULL) { set_option_value(arg, n, s, opt_flags); arg_end = p; } else { -- cgit From 8921035fc762d39f42f1b644a19a78d36fbda87a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Jul 2022 17:17:20 +0800 Subject: vim-patch:8.2.2284: Vim9: cannot set an option to a boolean value Problem: Vim9: cannot set an option to a boolean value. Solution: Check for VAR_BOOL. (closes vim/vim#7603) https://github.com/vim/vim/commit/31a201a04aa95708af5d62070d2d397a201cc1a5 --- src/nvim/eval/vars.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 091e3f87c4..40a3707060 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -1564,10 +1564,17 @@ static void getwinvar(typval_T *argvars, typval_T *rettv, int off) /// Set option "varname" to the value of "varp" for the current buffer/window. static void set_option_from_tv(const char *varname, typval_T *varp) { + long numval = 0; + const char *strval; bool error = false; char nbuf[NUMBUFLEN]; - const long numval = (long)tv_get_number_chk(varp, &error); - const char *const strval = tv_get_string_buf_chk(varp, nbuf); + + if (varp->v_type == VAR_BOOL) { + numval = (long)varp->vval.v_number; + } else { + numval = (long)tv_get_number_chk(varp, &error); + } + strval = tv_get_string_buf_chk(varp, nbuf); if (!error && strval != NULL) { set_option_value(varname, numval, strval, OPT_LOCAL); } -- cgit From 963ea726daf3e19279f8e24b48116f11f1921c7d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Jul 2022 17:20:23 +0800 Subject: vim-patch:8.2.2285: Vim9: cannot set an option to a false Problem: Vim9: cannot set an option to a false. Solution: For VAR_BOOL use string "0". (closes vim/vim#7603) https://github.com/vim/vim/commit/b0d8182fa39f2c9403f5f9a0663589fcab43a6c8 --- src/nvim/eval/vars.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 40a3707060..a0141402bc 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -1571,10 +1571,11 @@ static void set_option_from_tv(const char *varname, typval_T *varp) if (varp->v_type == VAR_BOOL) { numval = (long)varp->vval.v_number; + strval = "0"; // avoid using "false" } else { numval = (long)tv_get_number_chk(varp, &error); + strval = tv_get_string_buf_chk(varp, nbuf); } - strval = tv_get_string_buf_chk(varp, nbuf); if (!error && strval != NULL) { set_option_value(varname, numval, strval, OPT_LOCAL); } -- cgit From d8df9afad62a9a4beb4ec607f8e10d674de66dbe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 25 Jul 2022 18:11:37 +0800 Subject: vim-patch:8.2.2969: subtracting from number option fails when result is zero Problem: Subtracting from number option fails when result is zero. (Ingo Karkat) Solution: Reset the string value when using the numeric value. (closes vim/vim#8351) https://github.com/vim/vim/commit/a42e6e0082a6d564dbfa55317d4a698ac12ae898 Cherry-pick Test_compound_assignment_operators() changes from patch 8.2.1593 --- src/nvim/eval/vars.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index a0141402bc..152d1c3e00 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -663,6 +663,7 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo case '%': n = num_modulus(numval, n); break; } + s = NULL; } else if (opt_type == gov_string && stringval != NULL && s != NULL) { // string char *const oldstringval = stringval; -- cgit