mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Problem: Vim9: boolean evaluation does not work as intended. Solution: Use tv2bool() in Vim9 script. (closes #6681)
This commit is contained in:
@@ -192,6 +192,9 @@ eval_to_bool(
|
|||||||
*error = FALSE;
|
*error = FALSE;
|
||||||
if (!skip)
|
if (!skip)
|
||||||
{
|
{
|
||||||
|
if (in_vim9script())
|
||||||
|
retval = tv2bool(&tv);
|
||||||
|
else
|
||||||
retval = (tv_get_number_chk(&tv, error) != 0);
|
retval = (tv_get_number_chk(&tv, error) != 0);
|
||||||
clear_tv(&tv);
|
clear_tv(&tv);
|
||||||
}
|
}
|
||||||
@@ -3098,7 +3101,8 @@ eval7(
|
|||||||
|
|
||||||
// Apply prefixed "-" and "+" now. Matters especially when
|
// Apply prefixed "-" and "+" now. Matters especially when
|
||||||
// "->" follows.
|
// "->" follows.
|
||||||
if (ret == OK && evaluate && end_leader > start_leader)
|
if (ret == OK && evaluate && end_leader > start_leader
|
||||||
|
&& rettv->v_type != VAR_BLOB)
|
||||||
ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
|
ret = eval7_leader(rettv, TRUE, start_leader, &end_leader);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -3281,6 +3285,9 @@ eval7_leader(
|
|||||||
f = rettv->vval.v_float;
|
f = rettv->vval.v_float;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
if (in_vim9script() && end_leader[-1] == '!')
|
||||||
|
val = tv2bool(rettv);
|
||||||
|
else
|
||||||
val = tv_get_number_chk(rettv, &error);
|
val = tv_get_number_chk(rettv, &error);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
@@ -1750,6 +1750,7 @@ enddef
|
|||||||
|
|
||||||
|
|
||||||
def Test_expr7_not()
|
def Test_expr7_not()
|
||||||
|
let lines =<< trim END
|
||||||
assert_equal(true, !'')
|
assert_equal(true, !'')
|
||||||
assert_equal(true, ![])
|
assert_equal(true, ![])
|
||||||
assert_equal(false, !'asdf')
|
assert_equal(false, !'asdf')
|
||||||
@@ -1775,6 +1776,9 @@ def Test_expr7_not()
|
|||||||
|
|
||||||
assert_equal(true, !test_void())
|
assert_equal(true, !test_void())
|
||||||
assert_equal(true, !test_unknown())
|
assert_equal(true, !test_unknown())
|
||||||
|
END
|
||||||
|
CheckDefSuccess(lines)
|
||||||
|
CheckScriptSuccess(['vim9script'] + lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
func Test_expr7_fails()
|
func Test_expr7_fails()
|
||||||
|
@@ -1,5 +1,13 @@
|
|||||||
" Utility functions for testing vim9 script
|
" Utility functions for testing vim9 script
|
||||||
|
|
||||||
|
" Check that "lines" inside ":def" has no error.
|
||||||
|
func CheckDefSuccess(lines)
|
||||||
|
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
|
||||||
|
so Xdef
|
||||||
|
call Func()
|
||||||
|
call delete('Xdef')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Check that "lines" inside ":def" results in an "error" message.
|
" Check that "lines" inside ":def" results in an "error" message.
|
||||||
func CheckDefFailure(lines, error)
|
func CheckDefFailure(lines, error)
|
||||||
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
|
call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1416,
|
||||||
/**/
|
/**/
|
||||||
1415,
|
1415,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user