Skip to content

Commit d8585ed

Browse files
committed
patch 7.4.1816
Problem: Looping over a null list throws an error. Solution: Skip over the for loop.
1 parent 9a3b331 commit d8585ed

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/eval.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3292,11 +3292,16 @@ eval_for_line(
32923292
if (!skip)
32933293
{
32943294
l = tv.vval.v_list;
3295-
if (tv.v_type != VAR_LIST || l == NULL)
3295+
if (tv.v_type != VAR_LIST)
32963296
{
32973297
EMSG(_(e_listreq));
32983298
clear_tv(&tv);
32993299
}
3300+
else if (l == NULL)
3301+
{
3302+
/* a null list is like an empty list: do nothing */
3303+
clear_tv(&tv);
3304+
}
33003305
else
33013306
{
33023307
/* No need to increment the refcount, it's already set for the

src/testdir/test_expr.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ func Test_getreg_empty_list()
8383
call add(x, 'foo')
8484
call assert_equal(['foo'], y)
8585
endfunc
86+
87+
func Test_loop_over_null_list()
88+
let null_list = submatch(1, 1)
89+
for i in null_list
90+
call assert_true(0, 'should not get here')
91+
endfor
92+
endfunc

src/version.c

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

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
1816,
756758
/**/
757759
1815,
758760
/**/

0 commit comments

Comments
 (0)