Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
20952:c297dfafbc7d | 20953:6b4b887a12f0 |
---|---|
4657 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type); | 4657 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type); |
4658 break; | 4658 break; |
4659 } | 4659 } |
4660 } | 4660 } |
4661 | 4661 |
4662 void | |
4663 vim9_declare_error(char_u *name) | |
4664 { | |
4665 char *scope = ""; | |
4666 | |
4667 switch (*name) | |
4668 { | |
4669 case 'g': scope = " global"; break; | |
4670 case 'b': scope = " buffer"; break; | |
4671 case 'w': scope = " window"; break; | |
4672 case 't': scope = " tab"; break; | |
4673 case 'v': scope = " v:"; break; | |
4674 case '$': scope = "n environment"; break; | |
4675 } | |
4676 semsg(_(e_declare_var), scope, name); | |
4677 } | |
4678 | |
4662 /* | 4679 /* |
4663 * Compile declaration and assignment: | 4680 * Compile declaration and assignment: |
4664 * "let var", "let var = expr", "const var = expr" and "var = expr" | 4681 * "let var", "let var = expr", "const var = expr" and "var = expr" |
4665 * "arg" points to "var". | 4682 * "arg" points to "var". |
4666 * Return NULL for an error. | 4683 * Return NULL for an error. |
4853 { | 4870 { |
4854 dest = dest_env; | 4871 dest = dest_env; |
4855 type = &t_string; | 4872 type = &t_string; |
4856 if (is_decl) | 4873 if (is_decl) |
4857 { | 4874 { |
4858 semsg(_("E1065: Cannot declare an environment variable: %s"), | 4875 vim9_declare_error(name); |
4859 name); | |
4860 goto theend; | 4876 goto theend; |
4861 } | 4877 } |
4862 } | 4878 } |
4863 else if (*var_start == '@') | 4879 else if (*var_start == '@') |
4864 { | 4880 { |
4878 else if (STRNCMP(var_start, "g:", 2) == 0) | 4894 else if (STRNCMP(var_start, "g:", 2) == 0) |
4879 { | 4895 { |
4880 dest = dest_global; | 4896 dest = dest_global; |
4881 if (is_decl) | 4897 if (is_decl) |
4882 { | 4898 { |
4883 semsg(_(e_declare_global), name); | 4899 vim9_declare_error(name); |
4884 goto theend; | 4900 goto theend; |
4885 } | 4901 } |
4886 } | 4902 } |
4887 else if (STRNCMP(var_start, "b:", 2) == 0) | 4903 else if (STRNCMP(var_start, "b:", 2) == 0) |
4888 { | 4904 { |
4889 dest = dest_buffer; | 4905 dest = dest_buffer; |
4890 if (is_decl) | 4906 if (is_decl) |
4891 { | 4907 { |
4892 semsg(_("E1078: Cannot declare a buffer variable: %s"), | 4908 vim9_declare_error(name); |
4893 name); | |
4894 goto theend; | 4909 goto theend; |
4895 } | 4910 } |
4896 } | 4911 } |
4897 else if (STRNCMP(var_start, "w:", 2) == 0) | 4912 else if (STRNCMP(var_start, "w:", 2) == 0) |
4898 { | 4913 { |
4899 dest = dest_window; | 4914 dest = dest_window; |
4900 if (is_decl) | 4915 if (is_decl) |
4901 { | 4916 { |
4902 semsg(_("E1079: Cannot declare a window variable: %s"), | 4917 vim9_declare_error(name); |
4903 name); | |
4904 goto theend; | 4918 goto theend; |
4905 } | 4919 } |
4906 } | 4920 } |
4907 else if (STRNCMP(var_start, "t:", 2) == 0) | 4921 else if (STRNCMP(var_start, "t:", 2) == 0) |
4908 { | 4922 { |
4909 dest = dest_tab; | 4923 dest = dest_tab; |
4910 if (is_decl) | 4924 if (is_decl) |
4911 { | 4925 { |
4912 semsg(_("E1080: Cannot declare a tab variable: %s"), name); | 4926 vim9_declare_error(name); |
4913 goto theend; | 4927 goto theend; |
4914 } | 4928 } |
4915 } | 4929 } |
4916 else if (STRNCMP(var_start, "v:", 2) == 0) | 4930 else if (STRNCMP(var_start, "v:", 2) == 0) |
4917 { | 4931 { |
4930 dest = dest_vimvar; | 4944 dest = dest_vimvar; |
4931 vtv = get_vim_var_tv(vimvaridx); | 4945 vtv = get_vim_var_tv(vimvaridx); |
4932 type = typval2type(vtv); | 4946 type = typval2type(vtv); |
4933 if (is_decl) | 4947 if (is_decl) |
4934 { | 4948 { |
4935 semsg(_("E1064: Cannot declare a v: variable: %s"), name); | 4949 vim9_declare_error(name); |
4936 goto theend; | 4950 goto theend; |
4937 } | 4951 } |
4938 } | 4952 } |
4939 else | 4953 else |
4940 { | 4954 { |