Skip to content

Commit 227c58a

Browse files
committed
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.
1 parent 03717bf commit 227c58a

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

src/ex_docmd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,8 @@ do_cmdline(
11751175
*/
11761176
while (!((got_int
11771177
#ifdef FEAT_EVAL
1178-
|| (did_emsg && force_abort) || did_throw
1178+
|| (did_emsg && (force_abort || in_vim9script()))
1179+
|| did_throw
11791180
#endif
11801181
)
11811182
#ifdef FEAT_EVAL
@@ -1209,8 +1210,10 @@ do_cmdline(
12091210
/*
12101211
* If a sourced file or executed function ran to its end, report the
12111212
* unclosed conditional.
1213+
* In Vim9 script do not give a second error, executing aborts after
1214+
* the first one.
12121215
*/
1213-
if (!got_int && !did_throw
1216+
if (!got_int && !did_throw && !(did_emsg && in_vim9script())
12141217
&& ((getline_equal(fgetline, cookie, getsourceline)
12151218
&& !source_finished(fgetline, cookie))
12161219
|| (getline_equal(fgetline, cookie, get_func_line)

src/testdir/test_vim9_assign.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,14 +1768,14 @@ def Test_expr_error_no_assign()
17681768
var x = 1 / 0
17691769
echo x
17701770
END
1771-
CheckScriptFailureList(lines, ['E1154:', 'E121:'])
1771+
CheckScriptFailure(lines, 'E1154:')
17721772

17731773
lines =<< trim END
17741774
vim9script
17751775
var x = 1 % 0
17761776
echo x
17771777
END
1778-
CheckScriptFailureList(lines, ['E1154:', 'E121:'])
1778+
CheckScriptFailure(lines, 'E1154:')
17791779

17801780
lines =<< trim END
17811781
var x: string 'string'

src/testdir/test_vim9_func.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,17 +2592,17 @@ enddef
25922592
def Test_nested_lambda_in_closure()
25932593
var lines =<< trim END
25942594
vim9script
2595+
command WriteDone writefile(['Done'], 'XnestedDone')
25952596
def Outer()
25962597
def g:Inner()
25972598
echo map([1, 2, 3], {_, v -> v + 1})
25982599
enddef
25992600
g:Inner()
26002601
enddef
26012602
defcompile
2602-
writefile(['Done'], 'XnestedDone')
2603-
quit
2603+
# not reached
26042604
END
2605-
if !RunVim([], lines, '--clean')
2605+
if !RunVim([], lines, '--clean -c WriteDone -c quit')
26062606
return
26072607
endif
26082608
assert_equal(['Done'], readfile('XnestedDone'))

src/testdir/test_vim9_script.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,20 @@ def Test_error_in_nested_function()
854854
assert_equal(0, g:test_var)
855855
enddef
856856

857+
def Test_abort_after_error()
858+
var lines =<< trim END
859+
vim9script
860+
while true
861+
echo notfound
862+
endwhile
863+
g:gotthere = true
864+
END
865+
g:gotthere = false
866+
CheckScriptFailure(lines, 'E121:')
867+
assert_false(g:gotthere)
868+
unlet g:gotthere
869+
enddef
870+
857871
def Test_cexpr_vimscript()
858872
# only checks line continuation
859873
set errorformat=File\ %f\ line\ %l
@@ -3361,6 +3375,7 @@ def Test_vim9_autoload()
33613375
return 'test'
33623376
enddef
33633377
g:some#name = 'name'
3378+
g:some#dict = {key: 'value'}
33643379

33653380
def some#varargs(a1: string, ...l: list<string>): string
33663381
return a1 .. l[0] .. l[1]
@@ -3374,6 +3389,7 @@ def Test_vim9_autoload()
33743389

33753390
assert_equal('test', g:some#gettest())
33763391
assert_equal('name', g:some#name)
3392+
assert_equal('value', g:some#dict.key)
33773393
g:some#other = 'other'
33783394
assert_equal('other', g:some#other)
33793395

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2817,
753755
/**/
754756
2816,
755757
/**/

0 commit comments

Comments
 (0)