changeset 23497:2247a2ce3630 v8.2.2291

patch 8.2.2291: Vim9: cannot use "null" for v:null Commit: https://github.com/vim/vim/commit/67977821270bd328cd37c4ace38fb97f21ad4fd5 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 3 21:53:53 2021 +0100 patch 8.2.2291: Vim9: cannot use "null" for v:null Problem: Vim9: cannot use "null" for v:null. Solution: Support "null" like "true" and "false". (closes https://github.com/vim/vim/issues/7495)
author Bram Moolenaar <Bram@vim.org>
date Sun, 03 Jan 2021 22:00:04 +0100
parents 0e54f7d3c0ea
children 62e107d43ea2
files runtime/doc/vim9.txt src/evalvars.c src/testdir/test_vim9_expr.vim src/version.c src/vim9compile.c
diffstat 5 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/doc/vim9.txt
+++ b/runtime/doc/vim9.txt
@@ -1,4 +1,4 @@
-*vim9.txt*	For Vim version 8.2.  Last change: 2021 Jan 02
+*vim9.txt*	For Vim version 8.2.  Last change: 2021 Jan 03
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -640,11 +640,11 @@ always converted to string: >
 
 Simple types are string, float, special and bool.  For other types |string()|
 can be used.
-							*false* *true*
-In Vim9 script one can use "true" for v:true and "false" for v:false.  When
-converting a boolean to a string "false" and "true" are used, not "v:false"
-and "v:true" like in legacy script.  "v:none" and "v:null" are not changed,
-they are only used in JSON.
+							*false* *true* *null*
+In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
+for v:null.  When converting a boolean to a string "false" and "true" are
+used, not "v:false" and "v:true" like in legacy script.  "v:none" is not
+changed, it is only used in JSON and has no equivalent in other languages.
 
 Indexing a string with [idx] or [idx, idx] uses character indexes instead of
 byte indexes. Example: >
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2072,8 +2072,8 @@ get_var_special_name(int nr)
     {
 	case VVAL_FALSE: return in_vim9script() ? "false" : "v:false";
 	case VVAL_TRUE:  return in_vim9script() ? "true" : "v:true";
+	case VVAL_NULL:  return in_vim9script() ? "null" : "v:null";
 	case VVAL_NONE:  return "v:none";
-	case VVAL_NULL:  return "v:null";
     }
     internal_error("get_var_special_name()");
     return "42";
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -511,6 +511,8 @@ def Test_expr4_equal()
       assert_equal(true, v:none == v:none)
       assert_equal(false, v:none == v:null)
       assert_equal(true, g:anone == v:none)
+      assert_equal(true, null == v:null)
+      assert_equal(true, null == g:anull)
       assert_equal(false, v:none == g:anull)
 
       var nr0 = 0
@@ -1063,7 +1065,7 @@ def Test_expr5()
 
       assert_equal('atrue', 'a' .. true)
       assert_equal('afalse', 'a' .. false)
-      assert_equal('av:null', 'a' .. v:null)
+      assert_equal('anull', 'a' .. v:null)
       assert_equal('av:none', 'a' .. v:none)
       if has('float')
         assert_equal('a0.123', 'a' .. 0.123)
@@ -1657,6 +1659,7 @@ def Test_expr7_special()
       assert_equal(false, f)
 
       assert_equal(g:special_null, v:null)
+      assert_equal(g:special_null, null)
       assert_equal(g:special_none, v:none)
   END
   CheckDefAndScriptSuccess(lines)
--- 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 */
 /**/
+    2291,
+/**/
     2290,
 /**/
     2289,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3968,6 +3968,20 @@ compile_expr7(
 		    break;
 
 	/*
+	 * "null" constant
+	 */
+	case 'n':   if (STRNCMP(*arg, "null", 4) == 0
+						   && !eval_isnamec((*arg)[5]))
+		    {
+			*arg += 4;
+			rettv->v_type = VAR_SPECIAL;
+			rettv->vval.v_number = VVAL_NULL;
+		    }
+		    else
+			ret = NOTDONE;
+		    break;
+
+	/*
 	 * List: [expr, expr]
 	 */
 	case '[':   ret = compile_list(arg, cctx, ppconst);
@@ -5006,6 +5020,7 @@ assignment_len(char_u *p, int *heredoc)
 static char *reserved[] = {
     "true",
     "false",
+    "null",
     NULL
 };