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:
38
src/eval.c
38
src/eval.c
@@ -2196,6 +2196,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
long result = FALSE;
|
long result = FALSE;
|
||||||
typval_T var2;
|
typval_T var2;
|
||||||
int error;
|
int error;
|
||||||
|
int vim9script = in_vim9script();
|
||||||
|
|
||||||
if (evalarg == NULL)
|
if (evalarg == NULL)
|
||||||
{
|
{
|
||||||
@@ -2205,6 +2206,12 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
orig_flags = evalarg_used->eval_flags;
|
orig_flags = evalarg_used->eval_flags;
|
||||||
evaluate = orig_flags & EVAL_EVALUATE;
|
evaluate = orig_flags & EVAL_EVALUATE;
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
|
{
|
||||||
|
if (vim9script)
|
||||||
|
{
|
||||||
|
result = tv2bool(rettv);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
error = FALSE;
|
error = FALSE;
|
||||||
if (tv_get_number_chk(rettv, &error) != 0)
|
if (tv_get_number_chk(rettv, &error) != 0)
|
||||||
@@ -2213,6 +2220,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
if (error)
|
if (error)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Repeat until there is no following "||".
|
* Repeat until there is no following "||".
|
||||||
@@ -2235,6 +2243,14 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
* Compute the result.
|
* Compute the result.
|
||||||
*/
|
*/
|
||||||
if (evaluate && !result)
|
if (evaluate && !result)
|
||||||
|
{
|
||||||
|
if (vim9script)
|
||||||
|
{
|
||||||
|
clear_tv(rettv);
|
||||||
|
*rettv = var2;
|
||||||
|
result = tv2bool(rettv);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (tv_get_number_chk(&var2, &error) != 0)
|
if (tv_get_number_chk(&var2, &error) != 0)
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
@@ -2242,7 +2258,8 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
if (error)
|
if (error)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (evaluate)
|
}
|
||||||
|
if (evaluate && !vim9script)
|
||||||
{
|
{
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
rettv->vval.v_number = result;
|
rettv->vval.v_number = result;
|
||||||
@@ -2294,6 +2311,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
long result = TRUE;
|
long result = TRUE;
|
||||||
typval_T var2;
|
typval_T var2;
|
||||||
int error;
|
int error;
|
||||||
|
int vim9script = in_vim9script();
|
||||||
|
|
||||||
if (evalarg == NULL)
|
if (evalarg == NULL)
|
||||||
{
|
{
|
||||||
@@ -2303,6 +2321,12 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
orig_flags = evalarg_used->eval_flags;
|
orig_flags = evalarg_used->eval_flags;
|
||||||
evaluate = orig_flags & EVAL_EVALUATE;
|
evaluate = orig_flags & EVAL_EVALUATE;
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
|
{
|
||||||
|
if (vim9script)
|
||||||
|
{
|
||||||
|
result = tv2bool(rettv);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
error = FALSE;
|
error = FALSE;
|
||||||
if (tv_get_number_chk(rettv, &error) == 0)
|
if (tv_get_number_chk(rettv, &error) == 0)
|
||||||
@@ -2311,6 +2335,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
if (error)
|
if (error)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Repeat until there is no following "&&".
|
* Repeat until there is no following "&&".
|
||||||
@@ -2333,6 +2358,14 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
* Compute the result.
|
* Compute the result.
|
||||||
*/
|
*/
|
||||||
if (evaluate && result)
|
if (evaluate && result)
|
||||||
|
{
|
||||||
|
if (vim9script)
|
||||||
|
{
|
||||||
|
clear_tv(rettv);
|
||||||
|
*rettv = var2;
|
||||||
|
result = tv2bool(rettv);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (tv_get_number_chk(&var2, &error) == 0)
|
if (tv_get_number_chk(&var2, &error) == 0)
|
||||||
result = FALSE;
|
result = FALSE;
|
||||||
@@ -2340,7 +2373,8 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
|
|||||||
if (error)
|
if (error)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (evaluate)
|
}
|
||||||
|
if (evaluate && !vim9script)
|
||||||
{
|
{
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
rettv->vval.v_number = result;
|
rettv->vval.v_number = result;
|
||||||
|
@@ -127,7 +127,7 @@ def Test_expr2()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr2_vimscript()
|
def Test_expr2_vimscript()
|
||||||
" only checks line continuation
|
" check line continuation
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
let var = 0
|
let var = 0
|
||||||
@@ -141,7 +141,7 @@ def Test_expr2_vimscript()
|
|||||||
let var = v:false
|
let var = v:false
|
||||||
|| v:true
|
|| v:true
|
||||||
|| v:false
|
|| v:false
|
||||||
assert_equal(1, var)
|
assert_equal(v:true, var)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -150,7 +150,39 @@ def Test_expr2_vimscript()
|
|||||||
let var = v:false ||
|
let var = v:false ||
|
||||||
v:true ||
|
v:true ||
|
||||||
v:false
|
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
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
@@ -199,7 +231,7 @@ def Test_expr3()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr3_vimscript()
|
def Test_expr3_vimscript()
|
||||||
" only checks line continuation
|
" check line continuation
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
let var = 0
|
let var = 0
|
||||||
@@ -213,7 +245,7 @@ def Test_expr3_vimscript()
|
|||||||
let var = v:true
|
let var = v:true
|
||||||
&& v:true
|
&& v:true
|
||||||
&& v:true
|
&& v:true
|
||||||
assert_equal(1, var)
|
assert_equal(v:true, var)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -222,7 +254,43 @@ def Test_expr3_vimscript()
|
|||||||
let var = v:true &&
|
let var = v:true &&
|
||||||
v:true &&
|
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
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1205,
|
||||||
/**/
|
/**/
|
||||||
1204,
|
1204,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user