summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-03 21:53:53 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-03 21:53:53 +0100
commit67977821270bd328cd37c4ace38fb97f21ad4fd5 (patch)
treed375fe3cda573c60199ab49b6b7bcf8bff4926a9
parent2ef951dd31505874ae9ac35a18513ef34ae0ea3e (diff)
downloadvim-git-67977821270bd328cd37c4ace38fb97f21ad4fd5.tar.gz
patch 8.2.2291: Vim9: cannot use "null" for v:nullv8.2.2291
Problem: Vim9: cannot use "null" for v:null. Solution: Support "null" like "true" and "false". (closes #7495)
-rw-r--r--runtime/doc/vim9.txt12
-rw-r--r--src/evalvars.c2
-rw-r--r--src/testdir/test_vim9_expr.vim5
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c15
5 files changed, 28 insertions, 8 deletions
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt
index e13863a02..b30db0b86 100644
--- 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: >
diff --git a/src/evalvars.c b/src/evalvars.c
index c6b03e993..42ff828a5 100644
--- 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";
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index d22ece29d..e613f106b 100644
--- 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)
diff --git a/src/version.c b/src/version.c
index 558536544..4a42d4909 100644
--- 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,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 412f0c96c..3eae641f2 100644
--- 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
};