diff src/eval.c @ 21733:1bb5adfe5966 v8.2.1416

patch 8.2.1416: Vim9: boolean evaluation does not work as intended Commit: https://github.com/vim/vim/commit/3e06a1e2a8c0854c881574f33363e00264db1f1d Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 10 21:57:54 2020 +0200 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 https://github.com/vim/vim/issues/6681)
author Bram Moolenaar <Bram@vim.org>
date Mon, 10 Aug 2020 22:00:05 +0200
parents 741c1d58d50f
children fcf978444298
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -192,7 +192,10 @@ eval_to_bool(
 	*error = FALSE;
 	if (!skip)
 	{
-	    retval = (tv_get_number_chk(&tv, error) != 0);
+	    if (in_vim9script())
+		retval = tv2bool(&tv);
+	    else
+		retval = (tv_get_number_chk(&tv, error) != 0);
 	    clear_tv(&tv);
 	}
     }
@@ -3098,7 +3101,8 @@ eval7(
 
 		// Apply prefixed "-" and "+" now.  Matters especially when
 		// "->" 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);
 		break;
 
@@ -3281,7 +3285,10 @@ eval7_leader(
 	f = rettv->vval.v_float;
     else
 #endif
-	val = tv_get_number_chk(rettv, &error);
+	if (in_vim9script() && end_leader[-1] == '!')
+	    val = tv2bool(rettv);
+	else
+	    val = tv_get_number_chk(rettv, &error);
     if (error)
     {
 	clear_tv(rettv);