]> granicus.if.org Git - vim/commitdiff
patch 8.2.4508: Vim9: cannot assign to a global variable on the command line v8.2.4508
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Mar 2022 11:05:57 +0000 (11:05 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Mar 2022 11:05:57 +0000 (11:05 +0000)
Problem:    Vim9: cannot assign to a global variable on the command line.
Solution:   Allow using :vim9cmd for assignment on the command line.

src/evalvars.c
src/testdir/dumps/Test_vim9_reject_declaration_1.dump [moved from src/testdir/dumps/Test_vim9_reject_declaration.dump with 100% similarity]
src/testdir/dumps/Test_vim9_reject_declaration_2.dump [new file with mode: 0644]
src/testdir/test_vim9_script.vim
src/version.c

index 260c297b0ef839ab9b6a6a773c66c0aecddea3cb..40e643b9f37e20f8e5dd4fbfb1b5a181bc68340b 100644 (file)
@@ -754,12 +754,14 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
     void
 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)
+    if (current_sctx.sc_sid == 0 && checkforcmd_noparen(&p, "var", 3))
     {
        emsg(_(e_cannot_declare_variable_on_command_line));
        return;
diff --git a/src/testdir/dumps/Test_vim9_reject_declaration_2.dump b/src/testdir/dumps/Test_vim9_reject_declaration_2.dump
new file mode 100644 (file)
index 0000000..a6d516c
--- /dev/null
@@ -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| 
index 70a3ffbe3ca87e80f973f4ac11dc9a2430df7096..f60fb36bc3caf806dd11c90cf2249bd95cf448b2 100644 (file)
@@ -3365,7 +3365,10 @@ endfunc
 def Run_test_reject_declaration()
   var buf = g:RunVimInTerminal('', {'rows': 6})
   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
   g:StopVimInTerminal(buf)
index 2e22a77f8774afcba44fb777fbfdceb34d22df16..5bbd307c75d17dfb679bec65979a253f1dc2a7e5 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4508,
 /**/
     4507,
 /**/