Skip to content

Commit 69e4455

Browse files
committed
patch 8.2.1512: failure after trinary expression fails
Problem: Failure after trinary expression fails. Solution: Restore eval_flags. (Yasuhiro Matsumoto, closes #6776)
1 parent cd94277 commit 69e4455

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/eval.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,10 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21672167
evalarg_used->eval_flags = result ? orig_flags
21682168
: orig_flags & ~EVAL_EVALUATE;
21692169
if (eval1(arg, rettv, evalarg_used) == FAIL)
2170+
{
2171+
evalarg_used->eval_flags = orig_flags;
21702172
return FAIL;
2173+
}
21712174

21722175
/*
21732176
* Check for the ":".
@@ -2178,6 +2181,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21782181
emsg(_(e_missing_colon));
21792182
if (evaluate && result)
21802183
clear_tv(rettv);
2184+
evalarg_used->eval_flags = orig_flags;
21812185
return FAIL;
21822186
}
21832187
if (getnext)
@@ -2188,6 +2192,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
21882192
{
21892193
error_white_both(p, 1);
21902194
clear_tv(rettv);
2195+
evalarg_used->eval_flags = orig_flags;
21912196
return FAIL;
21922197
}
21932198
*arg = p;
@@ -2200,6 +2205,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
22002205
{
22012206
error_white_both(p, 1);
22022207
clear_tv(rettv);
2208+
evalarg_used->eval_flags = orig_flags;
22032209
return FAIL;
22042210
}
22052211
*arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
@@ -2209,6 +2215,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
22092215
{
22102216
if (evaluate && result)
22112217
clear_tv(rettv);
2218+
evalarg_used->eval_flags = orig_flags;
22122219
return FAIL;
22132220
}
22142221
if (evaluate && !result)

src/testdir/test_vim9_expr.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ def Test_expr1_vimscript()
114114
let var = v:true ? 1 :2
115115
END
116116
CheckScriptFailure(lines, 'E1004:', 2)
117+
118+
# check after failure eval_flags is reset
119+
lines =<< trim END
120+
vim9script
121+
try
122+
call eval('0 ? 1: 2')
123+
catch
124+
endtry
125+
assert_equal(v:true, eval(string(v:true)))
126+
END
127+
CheckScriptSuccess(lines)
128+
129+
lines =<< trim END
130+
vim9script
131+
try
132+
call eval('0 ? 1 :2')
133+
catch
134+
endtry
135+
assert_equal(v:true, eval(string(v:true)))
136+
END
137+
CheckScriptSuccess(lines)
117138
enddef
118139

119140
func Test_expr1_fails()

src/testdir/test_vimscript.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7445,6 +7445,30 @@ func Test_typed_script_var()
74457445
call StopVimInTerminal(buf)
74467446
endfunc
74477447

7448+
" Test for issue6776 {{{1
7449+
func Test_trinary_expression()
7450+
try
7451+
call eval('0 ? 0')
7452+
catch
7453+
endtry
7454+
" previous failure should not cause next expression to fail
7455+
call assert_equal(v:false, eval(string(v:false)))
7456+
7457+
try
7458+
call eval('0 ? "burp')
7459+
catch
7460+
endtry
7461+
" previous failure should not cause next expression to fail
7462+
call assert_equal(v:false, eval(string(v:false)))
7463+
7464+
try
7465+
call eval('1 ? 0 : "burp')
7466+
catch
7467+
endtry
7468+
" previous failure should not cause next expression to fail
7469+
call assert_equal(v:false, eval(string(v:false)))
7470+
endfunction
7471+
74487472
"-------------------------------------------------------------------------------
74497473
" Modelines {{{1
74507474
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

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+
1512,
757759
/**/
758760
1511,
759761
/**/

0 commit comments

Comments
 (0)