Mercurial > vim
diff src/vim9compile.c @ 20953:6b4b887a12f0 v8.2.1028
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Commit: https://github.com/vim/vim/commit/e55b1c098d9dc04c960e6575bb554b5130af8989
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 21 15:52:59 2020 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 21 Jun 2020 16:00:04 +0200 |
parents | 62912ad41aff |
children | 396fe712eb0f |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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 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 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 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 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 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 type = typval2type(vtv); if (is_decl) { - semsg(_("E1064: Cannot declare a v: variable: %s"), name); + vim9_declare_error(name); goto theend; } }