mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.1518: Vim9: cannot assign to local option
Problem: Vim9: cannot assign to local option. Solution: Skip over "&l:" and "&g:". (closes #6749)
This commit is contained in:
parent
6c53fca023
commit
2e80095501
@ -3242,6 +3242,27 @@ append_command(char_u *cmd)
|
|||||||
*d = NUL;
|
*d = NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If "start" points "&opt", "&l:opt", "&g:opt" or "$ENV" return a pointer to
|
||||||
|
* the name. Otherwise just return "start".
|
||||||
|
*/
|
||||||
|
char_u *
|
||||||
|
skip_option_env_lead(char_u *start)
|
||||||
|
{
|
||||||
|
char_u *name = start;
|
||||||
|
|
||||||
|
if (*start == '&')
|
||||||
|
{
|
||||||
|
if ((start[1] == 'l' || start[1] == 'g') && start[2] == ':')
|
||||||
|
name += 3;
|
||||||
|
else
|
||||||
|
name += 1;
|
||||||
|
}
|
||||||
|
else if (*start == '$')
|
||||||
|
name += 1;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find an Ex command by its name, either built-in or user.
|
* Find an Ex command by its name, either built-in or user.
|
||||||
* Start of the name can be found at eap->cmd.
|
* Start of the name can be found at eap->cmd.
|
||||||
@ -3273,9 +3294,7 @@ find_ex_command(
|
|||||||
p = eap->cmd;
|
p = eap->cmd;
|
||||||
if (lookup != NULL)
|
if (lookup != NULL)
|
||||||
{
|
{
|
||||||
// Skip over first char for "&opt = val", "$ENV = val" and "@r = val".
|
char_u *pskip = skip_option_env_lead(eap->cmd);
|
||||||
char_u *pskip = (*eap->cmd == '&' || *eap->cmd == '$')
|
|
||||||
? eap->cmd + 1 : eap->cmd;
|
|
||||||
|
|
||||||
if (vim_strchr((char_u *)"{('[\"@", *p) != NULL
|
if (vim_strchr((char_u *)"{('[\"@", *p) != NULL
|
||||||
|| ((p = to_name_const_end(pskip)) > eap->cmd && *p != NUL))
|
|| ((p = to_name_const_end(pskip)) > eap->cmd && *p != NUL))
|
||||||
|
@ -10,6 +10,7 @@ int parse_command_modifiers(exarg_T *eap, char **errormsg, int skip_only);
|
|||||||
void undo_cmdmod(exarg_T *eap, int save_msg_scroll);
|
void undo_cmdmod(exarg_T *eap, int save_msg_scroll);
|
||||||
int parse_cmd_address(exarg_T *eap, char **errormsg, int silent);
|
int parse_cmd_address(exarg_T *eap, char **errormsg, int silent);
|
||||||
int checkforcmd(char_u **pp, char *cmd, int len);
|
int checkforcmd(char_u **pp, char *cmd, int len);
|
||||||
|
char_u *skip_option_env_lead(char_u *start);
|
||||||
char_u *find_ex_command(exarg_T *eap, int *full, void *(*lookup)(char_u *, size_t, cctx_T *), cctx_T *cctx);
|
char_u *find_ex_command(exarg_T *eap, int *full, void *(*lookup)(char_u *, size_t, cctx_T *), cctx_T *cctx);
|
||||||
int modifier_len(char_u *cmd);
|
int modifier_len(char_u *cmd);
|
||||||
int cmd_exists(char_u *name);
|
int cmd_exists(char_u *name);
|
||||||
|
@ -110,12 +110,21 @@ def Test_assignment()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
|
||||||
&ts = 6
|
&ts = 6
|
||||||
&ts += 3
|
&ts += 3
|
||||||
assert_equal(9, &ts)
|
assert_equal(9, &ts)
|
||||||
|
|
||||||
|
&l:ts = 6
|
||||||
|
assert_equal(6, &ts)
|
||||||
|
&l:ts += 2
|
||||||
|
assert_equal(8, &ts)
|
||||||
|
|
||||||
|
&g:ts = 6
|
||||||
|
assert_equal(6, &g:ts)
|
||||||
|
&g:ts += 2
|
||||||
|
assert_equal(8, &g:ts)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
CheckDefFailure(['¬ex += 3'], 'E113:')
|
CheckDefFailure(['¬ex += 3'], 'E113:')
|
||||||
CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
|
CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
|
||||||
@ -163,19 +172,15 @@ def Test_assignment()
|
|||||||
call CheckDefFailure(['$SOME_ENV_VAR += "more"'], 'E1051:')
|
call CheckDefFailure(['$SOME_ENV_VAR += "more"'], 'E1051:')
|
||||||
call CheckDefFailure(['$SOME_ENV_VAR += 123'], 'E1012:')
|
call CheckDefFailure(['$SOME_ENV_VAR += 123'], 'E1012:')
|
||||||
|
|
||||||
@a = 'areg'
|
|
||||||
@a ..= 'add'
|
|
||||||
assert_equal('aregadd', @a)
|
|
||||||
call CheckDefFailure(['@a += "more"'], 'E1051:')
|
|
||||||
call CheckDefFailure(['@a += 123'], 'E1012:')
|
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
|
||||||
@c = 'areg'
|
@c = 'areg'
|
||||||
@c ..= 'add'
|
@c ..= 'add'
|
||||||
assert_equal('aregadd', @c)
|
assert_equal('aregadd', @c)
|
||||||
END
|
END
|
||||||
call CheckScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
|
call CheckDefFailure(['@a += "more"'], 'E1051:')
|
||||||
|
call CheckDefFailure(['@a += 123'], 'E1012:')
|
||||||
|
|
||||||
v:errmsg = 'none'
|
v:errmsg = 'none'
|
||||||
v:errmsg ..= 'again'
|
v:errmsg ..= 'again'
|
||||||
|
@ -41,6 +41,11 @@ def CheckScriptSuccess(lines: list<string>)
|
|||||||
delete('Xdef')
|
delete('Xdef')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def CheckDefAndScriptSuccess(lines: list<string>)
|
||||||
|
CheckDefSuccess(lines)
|
||||||
|
CheckScriptSuccess(['vim9script'] + lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
" Check that a command fails both when used in a :def function and when used
|
" Check that a command fails both when used in a :def function and when used
|
||||||
" in Vim9 script.
|
" in Vim9 script.
|
||||||
def CheckScriptAndDefFailure(lines: list<string>, error: string, lnum = -3)
|
def CheckScriptAndDefFailure(lines: list<string>, error: string, lnum = -3)
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
1518,
|
||||||
/**/
|
/**/
|
||||||
1517,
|
1517,
|
||||||
/**/
|
/**/
|
||||||
|
@ -4550,8 +4550,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
p = var_start + 2;
|
p = var_start + 2;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p = (*var_start == '&' || *var_start == '$')
|
// skip over the leading "&", "&l:", "&g:" and "$"
|
||||||
? var_start + 1 : var_start;
|
p = skip_option_env_lead(var_start);
|
||||||
p = to_name_end(p, TRUE);
|
p = to_name_end(p, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4595,8 +4595,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
}
|
}
|
||||||
cc = *p;
|
cc = *p;
|
||||||
*p = NUL;
|
*p = NUL;
|
||||||
opt_type = get_option_value(var_start + 1, &numval,
|
opt_type = get_option_value(skip_option_env_lead(var_start),
|
||||||
NULL, opt_flags);
|
&numval, NULL, opt_flags);
|
||||||
*p = cc;
|
*p = cc;
|
||||||
if (opt_type == -3)
|
if (opt_type == -3)
|
||||||
{
|
{
|
||||||
@ -5131,7 +5131,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
switch (dest)
|
switch (dest)
|
||||||
{
|
{
|
||||||
case dest_option:
|
case dest_option:
|
||||||
generate_STOREOPT(cctx, name + 1, opt_flags);
|
generate_STOREOPT(cctx, skip_option_env_lead(name),
|
||||||
|
opt_flags);
|
||||||
break;
|
break;
|
||||||
case dest_global:
|
case dest_global:
|
||||||
// include g: with the name, easier to execute that way
|
// include g: with the name, easier to execute that way
|
||||||
|
Loading…
x
Reference in New Issue
Block a user