mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1205: Vim9: && and || work different when not compiled
Problem: Vim9: && and || work different when not compiled. Solution: Keep the value.
This commit is contained in:
82
src/eval.c
82
src/eval.c
@@ -2196,6 +2196,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
long result = FALSE;
|
||||
typval_T var2;
|
||||
int error;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
if (evalarg == NULL)
|
||||
{
|
||||
@@ -2206,12 +2207,19 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
evaluate = orig_flags & EVAL_EVALUATE;
|
||||
if (evaluate)
|
||||
{
|
||||
error = FALSE;
|
||||
if (tv_get_number_chk(rettv, &error) != 0)
|
||||
result = TRUE;
|
||||
clear_tv(rettv);
|
||||
if (error)
|
||||
return FAIL;
|
||||
if (vim9script)
|
||||
{
|
||||
result = tv2bool(rettv);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = FALSE;
|
||||
if (tv_get_number_chk(rettv, &error) != 0)
|
||||
result = TRUE;
|
||||
clear_tv(rettv);
|
||||
if (error)
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2236,13 +2244,22 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
*/
|
||||
if (evaluate && !result)
|
||||
{
|
||||
if (tv_get_number_chk(&var2, &error) != 0)
|
||||
result = TRUE;
|
||||
clear_tv(&var2);
|
||||
if (error)
|
||||
return FAIL;
|
||||
if (vim9script)
|
||||
{
|
||||
clear_tv(rettv);
|
||||
*rettv = var2;
|
||||
result = tv2bool(rettv);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tv_get_number_chk(&var2, &error) != 0)
|
||||
result = TRUE;
|
||||
clear_tv(&var2);
|
||||
if (error)
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (evaluate)
|
||||
if (evaluate && !vim9script)
|
||||
{
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
rettv->vval.v_number = result;
|
||||
@@ -2294,6 +2311,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
long result = TRUE;
|
||||
typval_T var2;
|
||||
int error;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
if (evalarg == NULL)
|
||||
{
|
||||
@@ -2304,12 +2322,19 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
evaluate = orig_flags & EVAL_EVALUATE;
|
||||
if (evaluate)
|
||||
{
|
||||
error = FALSE;
|
||||
if (tv_get_number_chk(rettv, &error) == 0)
|
||||
result = FALSE;
|
||||
clear_tv(rettv);
|
||||
if (error)
|
||||
return FAIL;
|
||||
if (vim9script)
|
||||
{
|
||||
result = tv2bool(rettv);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = FALSE;
|
||||
if (tv_get_number_chk(rettv, &error) == 0)
|
||||
result = FALSE;
|
||||
clear_tv(rettv);
|
||||
if (error)
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2334,13 +2359,22 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
||||
*/
|
||||
if (evaluate && result)
|
||||
{
|
||||
if (tv_get_number_chk(&var2, &error) == 0)
|
||||
result = FALSE;
|
||||
clear_tv(&var2);
|
||||
if (error)
|
||||
return FAIL;
|
||||
if (vim9script)
|
||||
{
|
||||
clear_tv(rettv);
|
||||
*rettv = var2;
|
||||
result = tv2bool(rettv);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tv_get_number_chk(&var2, &error) == 0)
|
||||
result = FALSE;
|
||||
clear_tv(&var2);
|
||||
if (error)
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (evaluate)
|
||||
if (evaluate && !vim9script)
|
||||
{
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
rettv->vval.v_number = result;
|
||||
|
@@ -127,7 +127,7 @@ def Test_expr2()
|
||||
enddef
|
||||
|
||||
def Test_expr2_vimscript()
|
||||
" only checks line continuation
|
||||
" check line continuation
|
||||
let lines =<< trim END
|
||||
vim9script
|
||||
let var = 0
|
||||
@@ -141,7 +141,7 @@ def Test_expr2_vimscript()
|
||||
let var = v:false
|
||||
|| v:true
|
||||
|| v:false
|
||||
assert_equal(1, var)
|
||||
assert_equal(v:true, var)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
@@ -150,7 +150,39 @@ def Test_expr2_vimscript()
|
||||
let var = v:false ||
|
||||
v:true ||
|
||||
v:false
|
||||
assert_equal(1, var)
|
||||
assert_equal(v:true, var)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
" check keeping the value
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
assert_equal(2, 2 || 0)
|
||||
assert_equal(7, 0 ||
|
||||
0 ||
|
||||
7)
|
||||
assert_equal(0, 0 || 0)
|
||||
assert_equal(0, 0
|
||||
|| 0)
|
||||
assert_equal('', 0 || '')
|
||||
|
||||
g:vals = []
|
||||
assert_equal(3, Record(3) || Record(1))
|
||||
assert_equal([3], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(5, Record(0) || Record(5))
|
||||
assert_equal([0, 5], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(4, Record(0)
|
||||
|| Record(4)
|
||||
|| Record(0))
|
||||
assert_equal([0, 4], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(0, Record([]) || Record('') || Record(0))
|
||||
assert_equal([[], '', 0], g:vals)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
enddef
|
||||
@@ -199,7 +231,7 @@ def Test_expr3()
|
||||
enddef
|
||||
|
||||
def Test_expr3_vimscript()
|
||||
" only checks line continuation
|
||||
" check line continuation
|
||||
let lines =<< trim END
|
||||
vim9script
|
||||
let var = 0
|
||||
@@ -213,7 +245,7 @@ def Test_expr3_vimscript()
|
||||
let var = v:true
|
||||
&& v:true
|
||||
&& v:true
|
||||
assert_equal(1, var)
|
||||
assert_equal(v:true, var)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
@@ -222,7 +254,43 @@ def Test_expr3_vimscript()
|
||||
let var = v:true &&
|
||||
v:true &&
|
||||
v:true
|
||||
assert_equal(1, var)
|
||||
assert_equal(v:true, var)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
" check keeping the value
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
assert_equal(0, 2 && 0)
|
||||
assert_equal(0, 0 &&
|
||||
0 &&
|
||||
7)
|
||||
assert_equal(7, 2
|
||||
&& 3
|
||||
&& 7)
|
||||
assert_equal(0, 0 && 0)
|
||||
assert_equal(0, 0 && '')
|
||||
assert_equal('', 8 && '')
|
||||
|
||||
g:vals = []
|
||||
assert_equal(1, Record(3) && Record(1))
|
||||
assert_equal([3, 1], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(0, Record(0) && Record(5))
|
||||
assert_equal([0], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(0, Record(0) && Record(4) && Record(0))
|
||||
assert_equal([0], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(0, Record(8) && Record(4) && Record(0))
|
||||
assert_equal([8, 4, 0], g:vals)
|
||||
|
||||
g:vals = []
|
||||
assert_equal(0, Record([1]) && Record('z') && Record(0))
|
||||
assert_equal([[1], 'z', 0], g:vals)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
enddef
|
||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1205,
|
||||
/**/
|
||||
1204,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user