mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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 #6720)
This commit is contained in:
@@ -1294,28 +1294,36 @@ ex_let_one(
|
|||||||
emsg(_(e_letunexp));
|
emsg(_(e_letunexp));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long n;
|
long n = 0;
|
||||||
int opt_type;
|
int opt_type;
|
||||||
long numval;
|
long numval;
|
||||||
char_u *stringval = NULL;
|
char_u *stringval = NULL;
|
||||||
char_u *s = NULL;
|
char_u *s = NULL;
|
||||||
|
int failed = FALSE;
|
||||||
|
|
||||||
c1 = *p;
|
c1 = *p;
|
||||||
*p = NUL;
|
*p = NUL;
|
||||||
|
|
||||||
|
opt_type = get_option_value(arg, &numval, &stringval, opt_flags);
|
||||||
|
if ((opt_type == 1 || opt_type == -1)
|
||||||
|
&& (tv->v_type != VAR_STRING || !in_vim9script()))
|
||||||
|
// number, possibly hidden
|
||||||
n = (long)tv_get_number(tv);
|
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)
|
// Avoid setting a string option to the text "v:false" or similar.
|
||||||
s = tv_get_string_chk(tv); // != NULL if number or string
|
// In Vim9 script also don't convert a number to string.
|
||||||
if (s != NULL && op != NULL && *op != '=')
|
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL
|
||||||
|
&& (!in_vim9script() || tv->v_type != VAR_NUMBER))
|
||||||
|
s = tv_get_string_chk(tv);
|
||||||
|
|
||||||
|
if (op != NULL && *op != '=')
|
||||||
{
|
{
|
||||||
opt_type = get_option_value(arg, &numval,
|
|
||||||
&stringval, opt_flags);
|
|
||||||
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
|
||||||
{
|
{
|
||||||
@@ -1330,20 +1338,26 @@ ex_let_one(
|
|||||||
case '%': n = (long)num_modulus(numval, n); break;
|
case '%': n = (long)num_modulus(numval, n); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (opt_type == 0 && stringval != NULL) // string
|
else if (opt_type == 0 && stringval != NULL && s != NULL)
|
||||||
{
|
{
|
||||||
|
// string
|
||||||
s = concat_str(stringval, s);
|
s = concat_str(stringval, s);
|
||||||
vim_free(stringval);
|
vim_free(stringval);
|
||||||
stringval = s;
|
stringval = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s != NULL || tv->v_type == VAR_BOOL
|
|
||||||
|| tv->v_type == VAR_SPECIAL)
|
if (!failed)
|
||||||
|
{
|
||||||
|
if (opt_type != 0 || s != NULL)
|
||||||
{
|
{
|
||||||
set_option_value(arg, n, s, opt_flags);
|
set_option_value(arg, n, s, opt_flags);
|
||||||
arg_end = p;
|
arg_end = p;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
emsg(_(e_stringreq));
|
||||||
|
}
|
||||||
*p = c1;
|
*p = c1;
|
||||||
vim_free(stringval);
|
vim_free(stringval);
|
||||||
}
|
}
|
||||||
|
@@ -96,22 +96,36 @@ def Test_assignment()
|
|||||||
&ts += 3
|
&ts += 3
|
||||||
assert_equal(9, &ts)
|
assert_equal(9, &ts)
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
call CheckDefFailure(['¬ex += 3'], 'E113:')
|
CheckDefFailure(['¬ex += 3'], 'E113:')
|
||||||
call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
|
CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
|
||||||
call CheckDefFailure(['&ts = [7]'], 'E1012:')
|
CheckDefFailure(['&ts = [7]'], 'E1012:')
|
||||||
call CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list')
|
CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list')
|
||||||
call CheckDefFailure(['&ts = "xx"'], 'E1012:')
|
CheckDefFailure(['&ts = "xx"'], 'E1012:')
|
||||||
call CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string')
|
CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string')
|
||||||
call CheckDefFailure(['&path += 3'], 'E1012:')
|
CheckDefFailure(['&path += 3'], 'E1012:')
|
||||||
call CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
|
CheckDefExecFailure(['&bs = "asdf"'], 'E474:')
|
||||||
# test freeing ISN_STOREOPT
|
# test freeing ISN_STOREOPT
|
||||||
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
|
CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
|
||||||
&ts = 8
|
&ts = 8
|
||||||
|
|
||||||
call CheckDefFailure(['let s:var = 123'], 'E1101:')
|
lines =<< trim END
|
||||||
call CheckDefFailure(['let s:var: number'], 'E1101:')
|
let save_TI = &t_TI
|
||||||
|
&t_TI = ''
|
||||||
|
assert_equal('', &t_TI)
|
||||||
|
&t_TI = 'xxx'
|
||||||
|
assert_equal('xxx', &t_TI)
|
||||||
|
&t_TI = save_TI
|
||||||
|
END
|
||||||
|
CheckDefSuccess(lines)
|
||||||
|
CheckScriptSuccess(['vim9script'] + lines)
|
||||||
|
|
||||||
|
CheckDefFailure(['&t_TI = 123'], 'E1012:')
|
||||||
|
CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:')
|
||||||
|
|
||||||
|
CheckDefFailure(['let s:var = 123'], 'E1101:')
|
||||||
|
CheckDefFailure(['let s:var: number'], 'E1101:')
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1469,
|
||||||
/**/
|
/**/
|
||||||
1468,
|
1468,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user