forked from aniani/vim
patch 8.2.4508: Vim9: cannot assign to a global variable on the command line
Problem: Vim9: cannot assign to a global variable on the command line. Solution: Allow using :vim9cmd for assignment on the command line.
This commit is contained in:
@@ -754,12 +754,14 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
|
|||||||
void
|
void
|
||||||
ex_var(exarg_T *eap)
|
ex_var(exarg_T *eap)
|
||||||
{
|
{
|
||||||
|
char_u *p = eap->cmd;
|
||||||
|
|
||||||
if (!in_vim9script())
|
if (!in_vim9script())
|
||||||
{
|
{
|
||||||
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
|
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (current_sctx.sc_sid == 0)
|
if (current_sctx.sc_sid == 0 && checkforcmd_noparen(&p, "var", 3))
|
||||||
{
|
{
|
||||||
emsg(_(e_cannot_declare_variable_on_command_line));
|
emsg(_(e_cannot_declare_variable_on_command_line));
|
||||||
return;
|
return;
|
||||||
|
6
src/testdir/dumps/Test_vim9_reject_declaration_2.dump
Normal file
6
src/testdir/dumps/Test_vim9_reject_declaration_2.dump
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
> +0&#ffffff0@74
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|1+0#0000000&|2|3| @53|0|,|0|-|1| @8|A|l@1|
|
@@ -3365,7 +3365,10 @@ endfunc
|
|||||||
def Run_test_reject_declaration()
|
def Run_test_reject_declaration()
|
||||||
var buf = g:RunVimInTerminal('', {'rows': 6})
|
var buf = g:RunVimInTerminal('', {'rows': 6})
|
||||||
term_sendkeys(buf, ":vim9cmd var x: number\<CR>")
|
term_sendkeys(buf, ":vim9cmd var x: number\<CR>")
|
||||||
g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration', {})
|
g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration_1', {})
|
||||||
|
term_sendkeys(buf, ":\<CR>")
|
||||||
|
term_sendkeys(buf, ":vim9cmd g:foo = 123 | echo g:foo\<CR>")
|
||||||
|
g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration_2', {})
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
g:StopVimInTerminal(buf)
|
g:StopVimInTerminal(buf)
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4508,
|
||||||
/**/
|
/**/
|
||||||
4507,
|
4507,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user