patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Problem: Vim9: result of && and || expression cannot be assigned to a bool
at the script level.
Solution: Add the VAR_BOOL_OK flag. Convert to bool when needed.
diff --git a/src/vim9script.c b/src/vim9script.c
index ed1d6da..4816315 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -557,6 +557,7 @@
/*
* Check if the type of script variable "dest" allows assigning "value".
+ * If needed convert "value" to a bool.
*/
int
check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
@@ -575,12 +576,24 @@
if (sv->sv_tv == dest)
{
+ int ret;
+
if (sv->sv_const)
{
semsg(_(e_readonlyvar), name);
return FAIL;
}
- return check_typval_type(sv->sv_type, value, 0);
+ ret = check_typval_type(sv->sv_type, value, 0);
+ if (ret == OK && need_convert_to_bool(sv->sv_type, value))
+ {
+ int val = tv2bool(value);
+
+ clear_tv(value);
+ value->v_type = VAR_BOOL;
+ value->v_lock = 0;
+ value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE;
+ }
+ return ret;
}
}
iemsg("check_script_var_type(): not found");