patch 8.2.1798: Vim9: trinary operator condition is too permissive
Problem: Vim9: trinary operator condition is too permissive.
Solution: Use tv_get_bool_chk().
diff --git a/src/eval.c b/src/eval.c
index a678d32..285558d 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -191,7 +191,7 @@
if (!skip)
{
if (in_vim9script())
- retval = tv2bool(&tv);
+ retval = tv_get_bool_chk(&tv, error);
else
retval = (tv_get_number_chk(&tv, error) != 0);
clear_tv(&tv);
@@ -2143,6 +2143,7 @@
evalarg_T local_evalarg;
int orig_flags;
int evaluate;
+ int vim9script = in_vim9script();
if (evalarg == NULL)
{
@@ -2156,7 +2157,7 @@
*arg = eval_next_line(evalarg_used);
else
{
- if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
+ if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
{
error_white_both(p, 1);
clear_tv(rettv);
@@ -2170,8 +2171,10 @@
{
int error = FALSE;
- if (in_vim9script() || op_falsy)
+ if (op_falsy)
result = tv2bool(rettv);
+ else if (vim9script)
+ result = tv_get_bool_chk(rettv, &error);
else if (tv_get_number_chk(rettv, &error) != 0)
result = TRUE;
if (error || !op_falsy || !result)
@@ -2185,7 +2188,7 @@
*/
if (op_falsy)
++*arg;
- if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
+ if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
{
error_white_both(p, 1);
clear_tv(rettv);
@@ -2220,7 +2223,7 @@
*arg = eval_next_line(evalarg_used);
else
{
- if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
+ if (evaluate && vim9script && !VIM_ISWHITE(p[-1]))
{
error_white_both(p, 1);
clear_tv(rettv);
@@ -2233,7 +2236,7 @@
/*
* Get the third variable. Recursive!
*/
- if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
+ if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
{
error_white_both(p, 1);
clear_tv(rettv);