]> granicus.if.org Git - vim/commitdiff
patch 8.2.2817: Vim9: script sourcing continues after an error v8.2.2817
authorBram Moolenaar <Bram@vim.org>
Wed, 28 Apr 2021 18:40:44 +0000 (20:40 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 28 Apr 2021 18:40:44 +0000 (20:40 +0200)
Problem:    Vim9: script sourcing continues after an error.
Solution:   Make an error in any command in "vim9script" abort sourcing.

src/ex_docmd.c
src/testdir/test_vim9_assign.vim
src/testdir/test_vim9_func.vim
src/testdir/test_vim9_script.vim
src/version.c

index 1c41036a4aa7b9f2cd4b6842f6cc410376205c94..7811c8f7f30d124c304e14c7754e9ad01290df12 100644 (file)
@@ -1175,7 +1175,8 @@ do_cmdline(
      */
     while (!((got_int
 #ifdef FEAT_EVAL
-                   || (did_emsg && force_abort) || did_throw
+                   || (did_emsg && (force_abort || in_vim9script()))
+                   || did_throw
 #endif
             )
 #ifdef FEAT_EVAL
@@ -1209,8 +1210,10 @@ do_cmdline(
        /*
         * If a sourced file or executed function ran to its end, report the
         * unclosed conditional.
+        * In Vim9 script do not give a second error, executing aborts after
+        * the first one.
         */
-       if (!got_int && !did_throw
+       if (!got_int && !did_throw && !(did_emsg && in_vim9script())
                && ((getline_equal(fgetline, cookie, getsourceline)
                        && !source_finished(fgetline, cookie))
                    || (getline_equal(fgetline, cookie, get_func_line)
index fbc4d92af421b1edd38caed28859074adc380314..fa418b2ce289b9480550bb1b8b52dd8d53459dd4 100644 (file)
@@ -1768,14 +1768,14 @@ def Test_expr_error_no_assign()
       var x = 1 / 0
       echo x
   END
-  CheckScriptFailureList(lines, ['E1154:', 'E121:'])
+  CheckScriptFailure(lines, 'E1154:')
 
   lines =<< trim END
       vim9script
       var x = 1 % 0
       echo x
   END
-  CheckScriptFailureList(lines, ['E1154:', 'E121:'])
+  CheckScriptFailure(lines, 'E1154:')
 
   lines =<< trim END
       var x: string  'string'
index 5bfad6bcb4c86319471f9b44de20f2bcaee8793e..4d57eef71eec7fa0b921faa1a215e489a97d4b05 100644 (file)
@@ -2592,6 +2592,7 @@ enddef
 def Test_nested_lambda_in_closure()
   var lines =<< trim END
       vim9script
+      command WriteDone writefile(['Done'], 'XnestedDone')
       def Outer()
           def g:Inner()
               echo map([1, 2, 3], {_, v -> v + 1})
@@ -2599,10 +2600,9 @@ def Test_nested_lambda_in_closure()
           g:Inner()
       enddef
       defcompile
-      writefile(['Done'], 'XnestedDone')
-      quit
+      # not reached
   END
-  if !RunVim([], lines, '--clean')
+  if !RunVim([], lines, '--clean -c WriteDone -c quit')
     return
   endif
   assert_equal(['Done'], readfile('XnestedDone'))
index 1810c5bc82297ad39978e1b3ee76dcae86e41b72..0e77b58b638f09fc7411fc2b9c5ce8a3f5b8b4b8 100644 (file)
@@ -854,6 +854,20 @@ def Test_error_in_nested_function()
   assert_equal(0, g:test_var)
 enddef
 
+def Test_abort_after_error()
+  var lines =<< trim END
+      vim9script
+      while true
+        echo notfound
+      endwhile
+      g:gotthere = true
+  END
+  g:gotthere = false
+  CheckScriptFailure(lines, 'E121:')
+  assert_false(g:gotthere)
+  unlet g:gotthere
+enddef
+
 def Test_cexpr_vimscript()
   # only checks line continuation
   set errorformat=File\ %f\ line\ %l
@@ -3361,6 +3375,7 @@ def Test_vim9_autoload()
        return 'test'
      enddef
      g:some#name = 'name'
+     g:some#dict = {key: 'value'}
 
      def some#varargs(a1: string, ...l: list<string>): string
        return a1 .. l[0] .. l[1]
@@ -3374,6 +3389,7 @@ def Test_vim9_autoload()
 
   assert_equal('test', g:some#gettest())
   assert_equal('name', g:some#name)
+  assert_equal('value', g:some#dict.key)
   g:some#other = 'other'
   assert_equal('other', g:some#other)
 
index b1d5be79586cb3d3fe4db97395b37c1932cf21a7..0158d89470909e500c4de7caeb3355ba0d6ac8d5 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2817,
 /**/
     2816,
 /**/