Skip to content

Commit 3988f64

Browse files
committed
patch 8.2.1528: Vim9: :endif not found after "if false"
Problem: Vim9: :endif not found after "if false". Solution: When skipping still check for a following command. (closes #6797)
1 parent 601e76a commit 3988f64

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,14 @@ def Test_if_const_expr()
21222122
res = true
21232123
endif
21242124
assert_equal(false, res)
2125+
2126+
# with constant "false" expression may be invalid so long as the syntax is OK
2127+
if false | eval 0 | endif
2128+
if false | eval burp + 234 | endif
2129+
if false | echo burp 234 'asd' | endif
2130+
if false
2131+
burp
2132+
endif
21252133
enddef
21262134

21272135
def Test_if_const_expr_fails()

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1528,
757759
/**/
758760
1527,
759761
/**/

src/vim9compile.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4014,6 +4014,13 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
40144014
int ppconst_used = ppconst->pp_used;
40154015
char_u *next;
40164016

4017+
// Ignore all kinds of errors when not producing code.
4018+
if (cctx->ctx_skip == SKIP_YES)
4019+
{
4020+
skip_expr(arg);
4021+
return OK;
4022+
}
4023+
40174024
// Evaluate the first expression.
40184025
if (compile_expr2(arg, cctx, ppconst) == FAIL)
40194026
return FAIL;
@@ -6724,17 +6731,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
67246731

67256732
p = skipwhite(p);
67266733

6727-
if (cctx.ctx_skip == SKIP_YES
6728-
&& ea.cmdidx != CMD_if
6734+
if (cctx.ctx_had_return
67296735
&& ea.cmdidx != CMD_elseif
6730-
&& ea.cmdidx != CMD_else
6731-
&& ea.cmdidx != CMD_endif)
6732-
{
6733-
line = (char_u *)"";
6734-
continue;
6735-
}
6736-
6737-
if (ea.cmdidx != CMD_elseif
67386736
&& ea.cmdidx != CMD_else
67396737
&& ea.cmdidx != CMD_endif
67406738
&& ea.cmdidx != CMD_endfor
@@ -6743,11 +6741,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
67436741
&& ea.cmdidx != CMD_finally
67446742
&& ea.cmdidx != CMD_endtry)
67456743
{
6746-
if (cctx.ctx_had_return)
6747-
{
6748-
emsg(_(e_unreachable_code_after_return));
6749-
goto erret;
6750-
}
6744+
emsg(_(e_unreachable_code_after_return));
6745+
goto erret;
67516746
}
67526747

67536748
switch (ea.cmdidx)
@@ -6845,7 +6840,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
68456840
if (compile_expr0(&p, &cctx) == FAIL)
68466841
goto erret;
68476842

6848-
// drop the return value
6843+
// drop the result
68496844
generate_instr_drop(&cctx, ISN_DROP, 1);
68506845

68516846
line = skipwhite(p);
@@ -6859,7 +6854,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
68596854
line = compile_mult_expr(p, ea.cmdidx, &cctx);
68606855
break;
68616856

6862-
// TODO: other commands with an expression argument
6857+
// TODO: any other commands with an expression argument?
68636858

68646859
case CMD_append:
68656860
case CMD_change:
@@ -6870,8 +6865,14 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
68706865
goto erret;
68716866

68726867
case CMD_SIZE:
6873-
semsg(_(e_invalid_command_str), ea.cmd);
6874-
goto erret;
6868+
if (cctx.ctx_skip != SKIP_YES)
6869+
{
6870+
semsg(_(e_invalid_command_str), ea.cmd);
6871+
goto erret;
6872+
}
6873+
// We don't check for a next command here.
6874+
line = (char_u *)"";
6875+
break;
68756876

68766877
default:
68776878
// Not recognized, execute with do_cmdline_cmd().

0 commit comments

Comments
 (0)