Patch 8.2.4509
Problem: Vim9: can declare a variable with ":va".
Solution: Disallow using ":va", require using ":var".
Files: src/evalvars.c, src/errors.h, src/vim9compile.c,
src/testdir/test_vim9_assign.vim
*** ../vim-8.2.4508/src/evalvars.c 2022-03-05 11:05:32.290905138 +0000
--- src/evalvars.c 2022-03-05 11:19:13.268398835 +0000
***************
*** 755,771 ****
ex_var(exarg_T *eap)
{
char_u *p = eap->cmd;
if (!in_vim9script())
{
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
return;
}
! if (current_sctx.sc_sid == 0 && checkforcmd_noparen(&p, "var", 3))
{
emsg(_(e_cannot_declare_variable_on_command_line));
return;
}
ex_let(eap);
}
--- 755,778 ----
ex_var(exarg_T *eap)
{
char_u *p = eap->cmd;
+ int has_var;
if (!in_vim9script())
{
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
return;
}
! has_var = checkforcmd_noparen(&p, "var", 3);
! if (current_sctx.sc_sid == 0 && has_var)
{
emsg(_(e_cannot_declare_variable_on_command_line));
return;
}
+ if (eap->arg > eap->cmd && !has_var)
+ {
+ emsg(_(e_must_use_var_instead_of_va));
+ return;
+ }
ex_let(eap);
}
*** ../vim-8.2.4508/src/errors.h 2022-03-04 21:34:27.586422257 +0000
--- src/errors.h 2022-03-05 11:18:31.672375741 +0000
***************
*** 2762,2768 ****
EXTERN char e_yank_register_changed_while_using_it[]
INIT(= N_("E1064: Yank register changed while using it"));
#ifdef FEAT_EVAL
! // E1065 unused
EXTERN char e_cannot_declare_a_register_str[]
INIT(= N_("E1066: Cannot declare a register: %s"));
EXTERN char e_separator_mismatch_str[]
--- 2762,2769 ----
EXTERN char e_yank_register_changed_while_using_it[]
INIT(= N_("E1064: Yank register changed while using it"));
#ifdef FEAT_EVAL
! EXTERN char e_must_use_var_instead_of_va[]
! INIT(= N_("E1065: Must use :var instead of :va"));
EXTERN char e_cannot_declare_a_register_str[]
INIT(= N_("E1066: Cannot declare a register: %s"));
EXTERN char e_separator_mismatch_str[]
*** ../vim-8.2.4508/src/vim9compile.c 2022-02-23 22:11:58.778087741 +0000
--- src/vim9compile.c 2022-03-05 11:33:39.033913549 +0000
***************
*** 1883,1889 ****
lhs_T lhs;
long start_lnum = SOURCING_LNUM;
! // Skip over the "var" or "[var, var]" to get to any "=".
p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
if (p == NULL)
return *arg == '[' ? arg : NULL;
--- 1883,1896 ----
lhs_T lhs;
long start_lnum = SOURCING_LNUM;
! p = eap->cmd;
! if (eap->cmdidx == CMD_var && arg > p && !checkforcmd_noparen(&p, "var",
3))
! {
! emsg(_(e_must_use_var_instead_of_va));
! return NULL;
! }
!
! // Skip over the "varname" or "[varname, varname]" to get to any "=".
p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
if (p == NULL)
return *arg == '[' ? arg : NULL;
*** ../vim-8.2.4508/src/testdir/test_vim9_assign.vim 2022-03-03
17:05:17.527121052 +0000
--- src/testdir/test_vim9_assign.vim 2022-03-05 11:29:44.639247734 +0000
***************
*** 1965,1970 ****
--- 1965,1975 ----
v9.CheckDefFailure(['var foo.bar = 2'], 'E1087:')
v9.CheckDefFailure(['var foo[3] = 2'], 'E1087:')
v9.CheckDefFailure(['const foo: number'], 'E1021:')
+
+ lines =<< trim END
+ va foo = 123
+ END
+ v9.CheckDefAndScriptFailure(lines, 'E1065:', 1)
enddef
def Test_var_declaration_inferred()
*** ../vim-8.2.4508/src/version.c 2022-03-05 11:05:32.290905138 +0000
--- src/version.c 2022-03-05 11:27:55.448056032 +0000
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 4509,
/**/
--
Did you ever see a "Hit any key to continue" message in a music piece?
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220305113837.E74EA1C02C5%40moolenaar.net.