# HG changeset patch # User Bram Moolenaar # Date 1619635503 -7200 # Node ID 83877a1b66fd061bffc0f82222da0b8f1d78e0c8 # Parent 75f45e1281bed326bf4c2b9e74729a9322dcfbbc patch 8.2.2817: Vim9: script sourcing continues after an error Commit: https://github.com/vim/vim/commit/227c58a486d2459e7bf6ed2c917ede7e324e3570 Author: Bram Moolenaar Date: Wed Apr 28 20:40:44 2021 +0200 patch 8.2.2817: Vim9: script sourcing continues after an error Problem: Vim9: script sourcing continues after an error. Solution: Make an error in any command in "vim9script" abort sourcing. diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -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) diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -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' diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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')) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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 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) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2817, +/**/ 2816, /**/ 2815,