]> granicus.if.org Git - vim/commitdiff
patch 8.2.2725: Vim9: message about compiling is wrong when using try/catch v8.2.2725
authorBram Moolenaar <Bram@vim.org>
Mon, 5 Apr 2021 20:27:37 +0000 (22:27 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 5 Apr 2021 20:27:37 +0000 (22:27 +0200)
Problem:    Vim9: message about compiling is wrong when using try/catch.
Solution:   Store the compiling flag with the message. (closes #8071)

src/ex_docmd.c
src/ex_eval.c
src/structs.h
src/testdir/test_vim9_func.vim
src/version.c

index b4e35537d750ee9c2b897dbae6d70a3bacef7556..c8cb11ba7538b2f2990a6cf5c2d70da982ff7b45 100644 (file)
@@ -1266,7 +1266,7 @@ do_cmdline(
        if (did_throw)
        {
            char        *p = NULL;
-           msglist_T   *messages = NULL, *next;
+           msglist_T   *messages = NULL;
 
            /*
             * If the uncaught exception is a user exception, report it as an
@@ -1303,12 +1303,16 @@ do_cmdline(
            {
                do
                {
-                   next = messages->next;
+                   msglist_T   *next = messages->next;
+                   int         save_compiling = estack_compiling;
+
+                   estack_compiling = messages->msg_compiling;
                    emsg(messages->msg);
                    vim_free(messages->msg);
                    vim_free(messages->sfile);
                    vim_free(messages);
                    messages = next;
+                   estack_compiling = save_compiling;
                }
                while (messages != NULL);
            }
index 8d1fd87bcda00d722615b584d28a69dbe2cb3580..d68e792449f09477093962ce248d5cf9008f2371 100644 (file)
@@ -292,6 +292,7 @@ cause_errthrow(
                    // reaching do_errthrow().
                    elem->sfile = estack_sfile(ESTACK_NONE);
                    elem->slnum = SOURCING_LNUM;
+                   elem->msg_compiling = estack_compiling;
                }
            }
        }
index f0296c1e31588392f7ace1d03d83177d139afbbb..dd802152c23253037c67b7f4c0199b61389c37ca 100644 (file)
@@ -971,11 +971,12 @@ typedef struct {
 typedef struct msglist msglist_T;
 struct msglist
 {
+    msglist_T  *next;          // next of several messages in a row
     char       *msg;           // original message, allocated
     char       *throw_msg;     // msg to throw: usually original one
     char_u     *sfile;         // value from estack_sfile(), allocated
     long       slnum;          // line number for "sfile"
-    msglist_T  *next;          // next of several messages in a row
+    int                msg_compiling;  // saved value of estack_compiling
 };
 
 /*
index 5e3ca1c2c84fee2303d6a4c78736249e0ddfba1b..8085e5cf2284857e2ffb3520c243238287340cc7 100644 (file)
@@ -18,6 +18,7 @@ func Test_compiling_error()
   CheckRunVimInTerminal
 
   call TestCompilingError()
+  call TestCompilingErrorInTry()
 endfunc
 
 def TestCompilingError()
@@ -28,15 +29,49 @@ def TestCompilingError()
     enddef
     defcompile
   END
-  call writefile(lines, 'XTest_compile_error')
+  writefile(lines, 'XTest_compile_error')
   var buf = RunVimInTerminal('-S XTest_compile_error',
               {rows: 10, wait_for_ruler: 0})
-  call WaitForAssert(() => assert_match('Error detected while compiling command line.*Fails.*Variable not found: nothing',
+  WaitForAssert(() => assert_match('Error detected while compiling command line.*Fails.*Variable not found: nothing',
                      Term_getlines(buf, range(1, 9))))
 
   # clean up
-  call StopVimInTerminal(buf)
-  call delete('XTest_compile_error')
+  StopVimInTerminal(buf)
+  delete('XTest_compile_error')
+enddef
+
+def TestCompilingErrorInTry()
+  var dir = 'Xdir/autoload'
+  mkdir(dir, 'p')
+
+  var lines =<< trim END
+      vim9script
+      def script#OnlyCompiled()
+        g:runtime = 'yes'
+        invalid
+      enddef
+  END
+  writefile(lines, dir .. '/script.vim')
+
+  lines =<< trim END
+      vim9script
+      todo
+      try
+        script#OnlyCompiled()
+      catch /nothing/
+      endtry
+  END
+  lines[1] = 'set rtp=' .. getcwd() .. '/Xdir'
+  writefile(lines, 'XTest_compile_error')
+
+  var buf = RunVimInTerminal('-S XTest_compile_error', {rows: 10, wait_for_ruler: 0})
+  WaitForAssert(() => assert_match('Error detected while compiling command line.*function script#OnlyCompiled.*Invalid command: invalid',
+                     Term_getlines(buf, range(1, 9))))
+
+  # clean up
+  StopVimInTerminal(buf)
+  delete('XTest_compile_error')
+  delete('Xdir', 'rf')
 enddef
 
 def CallRecursive(n: number): number
index ef8f999ac80f642834aa478219cb44919b59224b..4318b71eb79634fed0852bbfd6f954813d159b07 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2725,
 /**/
     2724,
 /**/