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)
0aae4809fd
This commit is contained in:
zeertzjq 2022-07-25 16:56:11 +08:00
parent e9b58a619e
commit 3ea45a2caf

View File

@ -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)) { && vim_strchr(endchars, *skipwhite(p)) == NULL)) {
emsg(_(e_letunexp)); emsg(_(e_letunexp));
} else { } else {
varnumber_T n = 0;
int opt_type; int opt_type;
long numval; long numval;
char *stringval = NULL; char *stringval = NULL;
const char *s = NULL; const char *s = NULL;
bool failed = false;
const char c1 = *p; const char c1 = *p;
*p = NUL; *p = NUL;
varnumber_T n = tv_get_number(tv); opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) { if (opt_type == 1 || opt_type == -1) {
s = tv_get_string_chk(tv); // != NULL if number or string. // number, possibly hidden
n = (long)tv_get_number(tv);
} }
if (s != NULL && op != NULL && *op != '=') {
opt_type = get_option_value(arg, &numval, &stringval, opt_flags); // 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);
}
if (op != NULL && *op != '=') {
if ((opt_type == 1 && *op == '.') if ((opt_type == 1 && *op == '.')
|| (opt_type == 0 && *op != '.')) { || (opt_type == 0 && *op != '.')) {
semsg(_(e_letwrong), op); semsg(_(e_letwrong), op);
s = NULL; // don't set the value failed = true; // don't set the value
} else { } else {
if (opt_type == 1) { // number if (opt_type == 1) { // number
switch (*op) { switch (*op) {
@ -651,7 +659,8 @@ static char *ex_let_one(char *arg, typval_T *const tv, const bool copy, const bo
case '%': case '%':
n = num_modulus(numval, n); break; 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; char *const oldstringval = stringval;
stringval = (char *)concat_str((const char_u *)stringval, stringval = (char *)concat_str((const char_u *)stringval,
(const char_u *)s); (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) { if (!failed) {
set_option_value((const char *)arg, n, s, opt_flags); if (opt_type != 0 || s != NULL) {
arg_end = p; set_option_value(arg, n, s, opt_flags);
arg_end = p;
} else {
emsg(_(e_stringreq));
}
} }
*p = c1; *p = c1;
xfree(stringval); xfree(stringval);