]> granicus.if.org Git - vim/commitdiff
patch 8.2.3307: Vim9: :echoconsole cannot access local variables v8.2.3307
authorBram Moolenaar <Bram@vim.org>
Sat, 7 Aug 2021 13:05:47 +0000 (15:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 7 Aug 2021 13:05:47 +0000 (15:05 +0200)
Problem:    Vim9: :echoconsole cannot access local variables.
Solution:   Handle like other :echo commands. (closes #8708)

src/testdir/test_vim9_disassemble.vim
src/testdir/test_vim9_script.vim
src/version.c
src/vim9.h
src/vim9compile.c
src/vim9execute.c

index 1530c90a38689353d84bc9b0a0f5343c4df3335b..253fe1b06e62ea1dea5ed34ebb9fa7f2e4e4ddc6 100644 (file)
@@ -1938,6 +1938,7 @@ enddef
 
 def s:Echomsg()
   echomsg 'some' 'message'
+  echoconsole 'nothing'
   echoerr 'went' .. 'wrong'
 enddef
 
@@ -1948,6 +1949,9 @@ def Test_disassemble_echomsg()
         '\d PUSHS "some"\_s*' ..
         '\d PUSHS "message"\_s*' ..
         '\d ECHOMSG 2\_s*' ..
+        "echoconsole 'nothing'\\_s*" ..
+        '\d PUSHS "nothing"\_s*' ..
+        '\d ECHOCONSOLE 1\_s*' ..
         "echoerr 'went' .. 'wrong'\\_s*" ..
         '\d PUSHS "wentwrong"\_s*' ..
         '\d ECHOERR 1\_s*' ..
index 93dce833979a7f54371bc3bfc7bbdb6f6b79eefa..2c5e3e7dab0217554ffd49fe1f518233986802f7 100644 (file)
@@ -2493,10 +2493,11 @@ def Test_echomsg_cmd_vimscript()
 enddef
 
 def Test_echoerr_cmd()
+  var local = 'local'
   try
-    echoerr 'something' 'wrong' # comment
+    echoerr 'something' local 'wrong' # comment
   catch
-    assert_match('something wrong', v:exception)
+    assert_match('something local wrong', v:exception)
   endtry
 enddef
 
@@ -2515,6 +2516,12 @@ def Test_echoerr_cmd_vimscript()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_echoconsole_cmd()
+  var local = 'local'
+  echoconsole 'something' local # comment
+  # output goes anywhere
+enddef
+
 def Test_for_outside_of_function()
   var lines =<< trim END
     vim9script
index 652372d0f7b6ae9984f2a36e272a91589c1df688..9d5ede555a757bbf946299e152f0732edf2edc16 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3307,
 /**/
     3306,
 /**/
index 0011a5f7addd585be056bdf28733f16fc3953f82..da39949fa34271ce7ae98caa49c88f1b63d94a5c 100644 (file)
@@ -16,10 +16,11 @@ typedef enum {
     ISN_EXECCONCAT, // execute Ex command from isn_arg.number items on stack
     ISN_EXEC_SPLIT, // execute Ex command from isn_arg.string split at NL
     ISN_LEGACY_EVAL, // evaluate expression isn_arg.string with legacy syntax.
-    ISN_ECHO,      // echo isn_arg.echo.echo_count items on top of stack
-    ISN_EXECUTE,    // execute Ex commands isn_arg.number items on top of stack
-    ISN_ECHOMSG,    // echo Ex commands isn_arg.number items on top of stack
-    ISN_ECHOERR,    // echo Ex commands isn_arg.number items on top of stack
+    ISN_ECHO,      // :echo with isn_arg.echo.echo_count items on top of stack
+    ISN_EXECUTE,    // :execute with isn_arg.number items on top of stack
+    ISN_ECHOMSG,    // :echomsg with isn_arg.number items on top of stack
+    ISN_ECHOCONSOLE, // :echoconsole with isn_arg.number items on top of stack
+    ISN_ECHOERR,    // :echoerr with isn_arg.number items on top of stack
     ISN_RANGE,     // compute range from isn_arg.string, push to stack
     ISN_SUBSTITUTE, // :s command with expression
     ISN_INSTR,     // instructions compiled from expression
index 9d7af52a048549e862815e6e00d2fda493ca3515..5d625e0c75b9fd17f86ca2257e6d01c6f7f6ac2f 100644 (file)
@@ -8754,6 +8754,7 @@ compile_eval(char_u *arg, cctx_T *cctx)
  * compile "echo expr"
  * compile "echomsg expr"
  * compile "echoerr expr"
+ * compile "echoconsole expr"
  * compile "execute expr"
  */
     static char_u *
@@ -8804,6 +8805,8 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
            generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
        else if (cmdidx == CMD_echomsg)
            generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
+       else if (cmdidx == CMD_echoconsole)
+           generate_MULT_EXPR(cctx, ISN_ECHOCONSOLE, count);
        else
            generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
 
@@ -9861,7 +9864,7 @@ compile_def_function(
            case CMD_execute:
            case CMD_echomsg:
            case CMD_echoerr:
-           // TODO:  "echoconsole"
+           case CMD_echoconsole:
                    line = compile_mult_expr(p, ea.cmdidx, &cctx);
                    break;
 
@@ -10307,6 +10310,7 @@ delete_instr(isn_T *isn)
        case ISN_DEBUG:
        case ISN_DROP:
        case ISN_ECHO:
+       case ISN_ECHOCONSOLE:
        case ISN_ECHOERR:
        case ISN_ECHOMSG:
        case ISN_ENDTRY:
index 19a7a8d3e309e6a4be0f3ec4e7bb3f816c7b0d14..690b7e0b6292d720dba2ad0a027e107e12933cce 100644 (file)
@@ -1869,9 +1869,11 @@ exec_instructions(ectx_T *ectx)
 
            // :execute {string} ...
            // :echomsg {string} ...
+           // :echoconsole {string} ...
            // :echoerr {string} ...
            case ISN_EXECUTE:
            case ISN_ECHOMSG:
+           case ISN_ECHOCONSOLE:
            case ISN_ECHOERR:
                {
                    int         count = iptr->isn_arg.number;
@@ -1941,6 +1943,12 @@ exec_instructions(ectx_T *ectx)
                                msg_attr(ga.ga_data, echo_attr);
                                out_flush();
                            }
+                           else if (iptr->isn_type == ISN_ECHOCONSOLE)
+                           {
+                               ui_write(ga.ga_data, (int)STRLEN(ga.ga_data),
+                                                                        TRUE);
+                               ui_write((char_u *)"\r\n", 2, TRUE);
+                           }
                            else
                            {
                                SOURCING_LNUM = iptr->isn_lnum;
@@ -4900,15 +4908,19 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
                break;
            case ISN_EXECUTE:
                smsg("%s%4d EXECUTE %lld", pfx, current,
-                                           (varnumber_T)(iptr->isn_arg.number));
+                                         (varnumber_T)(iptr->isn_arg.number));
                break;
            case ISN_ECHOMSG:
                smsg("%s%4d ECHOMSG %lld", pfx, current,
-                                           (varnumber_T)(iptr->isn_arg.number));
+                                         (varnumber_T)(iptr->isn_arg.number));
+               break;
+           case ISN_ECHOCONSOLE:
+               smsg("%s%4d ECHOCONSOLE %lld", pfx, current,
+                                         (varnumber_T)(iptr->isn_arg.number));
                break;
            case ISN_ECHOERR:
                smsg("%s%4d ECHOERR %lld", pfx, current,
-                                           (varnumber_T)(iptr->isn_arg.number));
+                                         (varnumber_T)(iptr->isn_arg.number));
                break;
            case ISN_LOAD:
                {