mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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.
This commit is contained in:
@@ -43,6 +43,9 @@ def Test_expr1()
|
|||||||
var = 0
|
var = 0
|
||||||
assert_equal('two', var ? 'one' : 'two')
|
assert_equal('two', var ? 'one' : 'two')
|
||||||
|
|
||||||
|
# with constant condition expression is not evaluated
|
||||||
|
assert_equal('one', 1 ? 'one' : xxx)
|
||||||
|
|
||||||
let Some: func = function('len')
|
let Some: func = function('len')
|
||||||
let Other: func = function('winnr')
|
let Other: func = function('winnr')
|
||||||
let Res: func = g:atrue ? Some : Other
|
let Res: func = g:atrue ? Some : Other
|
||||||
@@ -139,7 +142,6 @@ enddef
|
|||||||
|
|
||||||
func Test_expr1_fails()
|
func Test_expr1_fails()
|
||||||
call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'", 1)
|
call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'", 1)
|
||||||
call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:", 1)
|
|
||||||
|
|
||||||
let msg = "white space required before and after '?'"
|
let msg = "white space required before and after '?'"
|
||||||
call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg, 1)
|
call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg, 1)
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1529,
|
||||||
/**/
|
/**/
|
||||||
1528,
|
1528,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -5519,6 +5519,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
|
|||||||
isn_T *isn;
|
isn_T *isn;
|
||||||
scope_T *scope = cctx->ctx_scope;
|
scope_T *scope = cctx->ctx_scope;
|
||||||
ppconst_T ppconst;
|
ppconst_T ppconst;
|
||||||
|
skip_T save_skip = cctx->ctx_skip;
|
||||||
|
|
||||||
if (scope == NULL || scope->se_type != IF_SCOPE)
|
if (scope == NULL || scope->se_type != IF_SCOPE)
|
||||||
{
|
{
|
||||||
@@ -5541,11 +5542,14 @@ compile_elseif(char_u *arg, cctx_T *cctx)
|
|||||||
|
|
||||||
// compile "expr"; if we know it evaluates to FALSE skip the block
|
// compile "expr"; if we know it evaluates to FALSE skip the block
|
||||||
CLEAR_FIELD(ppconst);
|
CLEAR_FIELD(ppconst);
|
||||||
|
if (cctx->ctx_skip == SKIP_YES)
|
||||||
|
cctx->ctx_skip = SKIP_UNKNOWN;
|
||||||
if (compile_expr1(&p, cctx, &ppconst) == FAIL)
|
if (compile_expr1(&p, cctx, &ppconst) == FAIL)
|
||||||
{
|
{
|
||||||
clear_ppconst(&ppconst);
|
clear_ppconst(&ppconst);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
cctx->ctx_skip = save_skip;
|
||||||
if (scope->se_skip_save == SKIP_YES)
|
if (scope->se_skip_save == SKIP_YES)
|
||||||
clear_ppconst(&ppconst);
|
clear_ppconst(&ppconst);
|
||||||
else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
|
else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
|
||||||
|
Reference in New Issue
Block a user