]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0197: Vim9: problem evaluating negated boolean logic v9.1.0197
authorYegappan Lakshmanan <yegappan@yahoo.com>
Fri, 22 Mar 2024 18:37:29 +0000 (19:37 +0100)
committerChristian Brabandt <cb@256bit.org>
Fri, 22 Mar 2024 18:37:29 +0000 (19:37 +0100)
Problem:  Vim9: problem evaluating negated boolean logic
          (lxhillwind)
Solution: Don't clear the first value on short circuit evaluation
          (Yegappan Lakshmanan)

fixes: #14265
closes: #14269

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9expr.c

index 6285ba124a316362e61addb7278a5bb79e73938b..7764b3791ba8e8dae9e4eb0ef1fa8a5100af26fe 100644 (file)
@@ -311,6 +311,33 @@ def Test_expr2()
       assert_equal([1], g:vals)
   END
   v9.CheckDefAndScriptSuccess(lines)
+
+  # test the short-circuit operation
+  lines =<< trim END
+    assert_equal(true, true && true)
+    assert_equal(false, true && !true)
+    assert_equal(false, !true && true)
+    assert_equal(false, !true && !true)
+
+    assert_equal(true, true || true)
+    assert_equal(true, true || !true)
+    assert_equal(true, !true || true)
+    assert_equal(false, !true || !true)
+
+    assert_equal(false, false && false)
+    assert_equal(false, false && !false)
+    assert_equal(false, !false && false)
+    assert_equal(true, !false && !false)
+
+    assert_equal(false, false || false)
+    assert_equal(true, false || !false)
+    assert_equal(true, !false || false)
+    assert_equal(true, !false || !false)
+
+    assert_equal(false, !true && !true && !true)
+    assert_equal(true, !false || !false || !false)
+  END
+  v9.CheckDefAndScriptSuccess(lines)
 enddef
 
 def Test_expr2_vimscript()
index ad9f6e1dfa1e390d6be4e0b42ec568e1cf1eea73..2c1cd161c9901808a1292afdc08ede95edd0215d 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    197,
 /**/
     196,
 /**/
index ee9712bfd9d5cf8f5eba620fb54d01e3fd850662..9d67aead59380cc6f3a308cb88da79b101c00b61 100644 (file)
@@ -2779,7 +2779,7 @@ compile_expr9(
     if (compile_subscript(arg, cctx, start_leader, &end_leader,
                                                             ppconst) == FAIL)
        return FAIL;
-    if (ppconst->pp_used > 0)
+    if ((ppconst->pp_used > 0) && (cctx->ctx_skip != SKIP_YES))
     {
        // apply the '!', '-' and '+' before the constant
        rettv = &ppconst->pp_tv[ppconst->pp_used - 1];