changeset 22606:336ac63fb987 v8.2.1851

patch 8.2.1851: Vim9: "!" followed by space incorrectly used Commit: https://github.com/vim/vim/commit/27491cd3ef86c10a2b64bcb657f29e1d0fccb183 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 15 21:54:56 2020 +0200 patch 8.2.1851: Vim9: "!" followed by space incorrectly used Problem: Vim9: "!" followed by space incorrectly used. Solution: Skip over trailing spaces. (closes https://github.com/vim/vim/issues/7131)
author Bram Moolenaar <Bram@vim.org>
date Thu, 15 Oct 2020 22:00:04 +0200
parents 79ac2ddec7e0
children 95b74784c037
files src/eval.c src/testdir/test_vim9_expr.vim src/version.c src/vim9compile.c
diffstat 4 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -3390,10 +3390,14 @@ eval7_leader(
 	f = rettv->vval.v_float;
     else
 #endif
+    {
+	while (VIM_ISWHITE(end_leader[-1]))
+	    --end_leader;
 	if (in_vim9script() && end_leader[-1] == '!')
 	    val = tv2bool(rettv);
 	else
 	    val = tv_get_number_chk(rettv, &error);
+    }
     if (error)
     {
 	clear_tv(rettv);
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -2292,6 +2292,22 @@ def Test_expr7_not()
       assert_equal(true, !!'asdf')
       assert_equal(true, !![2])
 
+      assert_equal(true, ! false)
+      assert_equal(true, !! true)
+      assert_equal(true, ! ! true)
+      assert_equal(true, !!! false)
+      assert_equal(true, ! ! ! false)
+
+      g:true = true
+      g:false = false
+      assert_equal(true, ! g:false)
+      assert_equal(true, !! g:true)
+      assert_equal(true, ! ! g:true)
+      assert_equal(true, !!! g:false)
+      assert_equal(true, ! ! ! g:false)
+      unlet g:true
+      unlet g:false
+
       assert_equal(true, !test_null_partial())
       assert_equal(false, !{-> 'yes'})
 
@@ -2314,8 +2330,7 @@ def Test_expr7_not()
       assert_equal(false, ![1, 2, 3]->reverse())
       assert_equal(true, ![]->reverse())
   END
-  CheckDefSuccess(lines)
-  CheckScriptSuccess(['vim9script'] + lines)
+  CheckDefAndScriptSuccess(lines)
 enddef
 
 func Test_expr7_fails()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1851,
+/**/
     1850,
 /**/
     1849,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3041,7 +3041,7 @@ apply_leader(typval_T *rettv, int numeri
 	    ++p;
 	    break;
 	}
-	else
+	else if (*p == '!')
 	{
 	    int v = tv2bool(rettv);
 
@@ -3178,12 +3178,13 @@ compile_leader(cctx_T *cctx, int numeric
 	}
 	else
 	{
-	    int  invert = TRUE;
-
-	    while (p > start && p[-1] == '!')
+	    int  invert = *p == '!';
+
+	    while (p > start && (p[-1] == '!' || VIM_ISWHITE(p[-1])))
 	    {
+		if (p[-1] == '!')
+		    invert = !invert;
 		--p;
-		invert = !invert;
 	    }
 	    if (generate_2BOOL(cctx, invert) == FAIL)
 		return FAIL;