changeset 21307:b991565745fb v8.2.1204

patch 8.2.1204: Vim9: true and false not recognized in Vim9 script Commit: https://github.com/vim/vim/commit/5d2eb0fff0fbe905da2c57fd73f7f127a73d1c99 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 13 21:59:33 2020 +0200 patch 8.2.1204: Vim9: true and false not recognized in Vim9 script Problem: Vim9: true and false not recognized in Vim9 script. Solution: Recognize true and false.
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Jul 2020 22:00:04 +0200
parents f8637d807598
children aade77a021b5
files src/eval.c src/testdir/test_vim9_expr.vim src/version.c
diffstat 3 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -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
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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, [])
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1204,
+/**/
     1203,
 /**/
     1202,