diff src/vim9script.c @ 22202:7899b4e2880c v8.2.1650

patch 8.2.1650: Vim9: result of && and || expression is not bool in script Commit: https://github.com/vim/vim/commit/c1ec0422e43720d2e96627605532ee9806c0789f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 9 22:27:58 2020 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Sep 2020 22:30:04 +0200
parents a9e60176dcd3
children dd42235ed626
line wrap: on
line diff
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -557,6 +557,7 @@ vim9_declare_scriptvar(exarg_T *eap, cha
 
 /*
  * 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 @@ check_script_var_type(typval_T *dest, ty
 
 	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");