0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable

Problem:    Vim9: no error for declaring buffer, window, etc. variable.
Solution:   Give an error.  Unify the error messages.
This commit is contained in:
Bram Moolenaar
2020-06-21 15:52:59 +02:00
parent 820ffa567c
commit e55b1c098d
7 changed files with 75 additions and 23 deletions

View File

@@ -4659,6 +4659,23 @@ generate_loadvar(
}
}
void
vim9_declare_error(char_u *name)
{
char *scope = "";
switch (*name)
{
case 'g': scope = " global"; break;
case 'b': scope = " buffer"; break;
case 'w': scope = " window"; break;
case 't': scope = " tab"; break;
case 'v': scope = " v:"; break;
case '$': scope = "n environment"; break;
}
semsg(_(e_declare_var), scope, name);
}
/*
* Compile declaration and assignment:
* "let var", "let var = expr", "const var = expr" and "var = expr"
@@ -4855,8 +4872,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
type = &t_string;
if (is_decl)
{
semsg(_("E1065: Cannot declare an environment variable: %s"),
name);
vim9_declare_error(name);
goto theend;
}
}
@@ -4880,7 +4896,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_global;
if (is_decl)
{
semsg(_(e_declare_global), name);
vim9_declare_error(name);
goto theend;
}
}
@@ -4889,8 +4905,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_buffer;
if (is_decl)
{
semsg(_("E1078: Cannot declare a buffer variable: %s"),
name);
vim9_declare_error(name);
goto theend;
}
}
@@ -4899,8 +4914,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_window;
if (is_decl)
{
semsg(_("E1079: Cannot declare a window variable: %s"),
name);
vim9_declare_error(name);
goto theend;
}
}
@@ -4909,7 +4923,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_tab;
if (is_decl)
{
semsg(_("E1080: Cannot declare a tab variable: %s"), name);
vim9_declare_error(name);
goto theend;
}
}
@@ -4932,7 +4946,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
type = typval2type(vtv);
if (is_decl)
{
semsg(_("E1064: Cannot declare a v: variable: %s"), name);
vim9_declare_error(name);
goto theend;
}
}