]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1204: Vim9: true and false not recognized in Vim9 script v8.2.1204
authorBram Moolenaar <Bram@vim.org>
Mon, 13 Jul 2020 19:59:33 +0000 (21:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 13 Jul 2020 19:59:33 +0000 (21:59 +0200)
Problem:    Vim9: true and false not recognized in Vim9 script.
Solution:   Recognize true and false.

src/eval.c
src/testdir/test_vim9_expr.vim
src/version.c

index 14c2849e829aa66adf0c7ef9de8b2d3a38a161ed..c5241513044c161dc117ea7f3a25aaec28e36952 100644 (file)
@@ -3079,8 +3079,22 @@ eval7(
            else if (flags & EVAL_CONSTANT)
                ret = FAIL;
            else if (evaluate)
-               // get value of variable
-               ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE);
+           {
+               // get the value of "true", "false" or a variable
+               if (len == 4 && in_vim9script() && STRNCMP(s, "true", 4) == 0)
+               {
+                   rettv->v_type = VAR_BOOL;
+                   rettv->vval.v_number = VVAL_TRUE;
+               }
+               else if (len == 5 && in_vim9script()
+                                               && STRNCMP(s, "false", 4) == 0)
+               {
+                   rettv->v_type = VAR_BOOL;
+                   rettv->vval.v_number = VVAL_FALSE;
+               }
+               else
+                   ret = eval_variable(s, len, rettv, NULL, TRUE, FALSE);
+           }
            else
            {
                // skip the name
index ede464e519e75817f3b3e25d3a3d66c30b51d628..cba41e395bbcb107b9a2b0c1384845ba2d4f37b8 100644 (file)
@@ -1024,6 +1024,19 @@ def Test_expr7_special()
   call CheckDefFailure(['v:none = 22'], 'E46:')
 enddef
 
+def Test_expr7_special_vim9script()
+  let lines =<< trim END
+      vim9script
+      let t = true
+      let f = false
+      assert_equal(v:true, true)
+      assert_equal(true, t)
+      assert_equal(v:false, false)
+      assert_equal(false, f)
+  END
+  CheckScriptSuccess(lines)
+enddef
+
 def Test_expr7_list()
   " list
   assert_equal(g:list_empty, [])
index fa57356e34f7dd7183b54fc6d0f6cc6fe2af4ac6..49896f7ff82706bf95e2f1335920cef0883850d9 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1204,
 /**/
     1203,
 /**/