Skip to content

Commit 749639e

Browse files
committed
patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Problem: Vim9: :elseif may be compiled when not needed. Solution: Do evaluate the :elseif expression.
1 parent 3988f64 commit 749639e

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def Test_expr1()
4343
var = 0
4444
assert_equal('two', var ? 'one' : 'two')
4545

46+
# with constant condition expression is not evaluated
47+
assert_equal('one', 1 ? 'one' : xxx)
48+
4649
let Some: func = function('len')
4750
let Other: func = function('winnr')
4851
let Res: func = g:atrue ? Some : Other
@@ -139,7 +142,6 @@ enddef
139142

140143
func Test_expr1_fails()
141144
call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'", 1)
142-
call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:", 1)
143145

144146
let msg = "white space required before and after '?'"
145147
call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg, 1)

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+
1529,
757759
/**/
758760
1528,
759761
/**/

src/vim9compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5519,6 +5519,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
55195519
isn_T *isn;
55205520
scope_T *scope = cctx->ctx_scope;
55215521
ppconst_T ppconst;
5522+
skip_T save_skip = cctx->ctx_skip;
55225523

55235524
if (scope == NULL || scope->se_type != IF_SCOPE)
55245525
{
@@ -5541,11 +5542,14 @@ compile_elseif(char_u *arg, cctx_T *cctx)
55415542

55425543
// compile "expr"; if we know it evaluates to FALSE skip the block
55435544
CLEAR_FIELD(ppconst);
5545+
if (cctx->ctx_skip == SKIP_YES)
5546+
cctx->ctx_skip = SKIP_UNKNOWN;
55445547
if (compile_expr1(&p, cctx, &ppconst) == FAIL)
55455548
{
55465549
clear_ppconst(&ppconst);
55475550
return NULL;
55485551
}
5552+
cctx->ctx_skip = save_skip;
55495553
if (scope->se_skip_save == SKIP_YES)
55505554
clear_ppconst(&ppconst);
55515555
else if (instr->ga_len == instr_count && ppconst.pp_used == 1)

0 commit comments

Comments
 (0)