1
0
forked from aniani/vim

patch 8.2.1355: Vim9: no error using :let for options and registers

Problem:    Vim9: no error using :let for options and registers.
Solution:   Give an error. (closes #6568)
This commit is contained in:
Bram Moolenaar 2020-08-02 16:59:00 +02:00
parent aa970abd0a
commit c2ee44cc38
4 changed files with 36 additions and 48 deletions

View File

@ -1219,6 +1219,13 @@ ex_let_one(
int opt_flags;
char_u *tofree = NULL;
if (in_vim9script() && (flags & LET_NO_COMMAND) == 0
&& vim_strchr((char_u *)"$@&", *arg) != NULL)
{
vim9_declare_error(arg);
return NULL;
}
// ":let $VAR = expr": Set environment variable.
if (*arg == '$')
{
@ -1227,11 +1234,6 @@ ex_let_one(
emsg(_("E996: Cannot lock an environment variable"));
return NULL;
}
if (in_vim9script() && (flags & LET_NO_COMMAND) == 0)
{
vim9_declare_error(arg);
return NULL;
}
// Find the end of the name.
++arg;
@ -2427,7 +2429,7 @@ eval_variable(
else
{
scriptitem_T *si = SCRIPT_ITEM(import->imp_sid);
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
+ import->imp_var_vals_idx;
tv = sv->sv_tv;
}

View File

@ -463,13 +463,16 @@ def Test_assignment_failure()
'[x, y; z] = [1]'], 'E1093:')
call CheckDefFailure(['let somevar'], "E1022:")
call CheckDefFailure(['let &option'], 'E1052:')
call CheckDefFailure(['let &tabstop = 4'], 'E1052:')
call CheckDefFailure(['&g:option = 5'], 'E113:')
call CheckScriptFailure(['vim9script', 'let &tabstop = 4'], 'E1052:')
call CheckDefFailure(['let $VAR = 5'], 'E1016: Cannot declare an environment variable:')
call CheckScriptFailure(['vim9script', 'let $ENV = "xxx"'], 'E1016:')
call CheckDefFailure(['let @~ = 5'], 'E354:')
call CheckDefFailure(['let @a = 5'], 'E1066:')
call CheckScriptFailure(['vim9script', 'let @a = "abc"'], 'E1066:')
call CheckDefFailure(['let g:var = 5'], 'E1016: Cannot declare a global variable:')
call CheckDefFailure(['let w:var = 5'], 'E1016: Cannot declare a window variable:')

View File

@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1355,
/**/
1354,
/**/

View File

@ -5067,7 +5067,12 @@ vim9_declare_error(char_u *name)
case 'w': scope = _("window"); break;
case 't': scope = _("tab"); break;
case 'v': scope = "v:"; break;
case '$': semsg(_(e_declare_env_var), name); return;
case '$': semsg(_(e_declare_env_var), name);
return;
case '&': semsg(_("E1052: Cannot declare an option: %s"), name);
return;
case '@': semsg(_("E1066: Cannot declare a register: %s"), name);
return;
default: return;
}
semsg(_(e_declare_var), scope, name);
@ -5229,6 +5234,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
if (cctx->ctx_skip != SKIP_YES)
{
int declare_error = FALSE;
if (*var_start == '&')
{
int cc;
@ -5240,11 +5247,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
emsg(_(e_const_option));
goto theend;
}
if (is_decl)
{
semsg(_("E1052: Cannot declare an option: %s"), var_start);
goto theend;
}
declare_error = is_decl;
p = var_start;
p = find_option_end(&p, &opt_flags);
if (p == NULL)
@ -5272,11 +5275,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
{
dest = dest_env;
type = &t_string;
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else if (*var_start == '@')
{
@ -5287,47 +5286,27 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
}
dest = dest_reg;
type = &t_string;
if (is_decl)
{
semsg(_("E1066: Cannot declare a register: %s"), name);
goto theend;
}
declare_error = is_decl;
}
else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0)
{
dest = dest_global;
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0)
{
dest = dest_buffer;
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0)
{
dest = dest_window;
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0)
{
dest = dest_tab;
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0)
{
@ -5346,11 +5325,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_vimvar;
vtv = get_vim_var_tv(vimvaridx);
type = typval2type_vimvar(vtv, cctx->ctx_type_list);
if (is_decl)
{
vim9_declare_error(name);
goto theend;
}
declare_error = is_decl;
}
else
{
@ -5439,6 +5414,12 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
goto theend;
}
}
if (declare_error)
{
vim9_declare_error(name);
goto theend;
}
}
// handle "a:name" as a name, not index "name" on "a"