Skip to content

Commit 6797782

Browse files
committed
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 #7495)
1 parent 2ef951d commit 6797782

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

runtime/doc/vim9.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9.txt* For Vim version 8.2. Last change: 2021 Jan 02
1+
*vim9.txt* For Vim version 8.2. Last change: 2021 Jan 03
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -640,11 +640,11 @@ always converted to string: >
640640
641641
Simple types are string, float, special and bool. For other types |string()|
642642
can be used.
643-
*false* *true*
644-
In Vim9 script one can use "true" for v:true and "false" for v:false. When
645-
converting a boolean to a string "false" and "true" are used, not "v:false"
646-
and "v:true" like in legacy script. "v:none" and "v:null" are not changed,
647-
they are only used in JSON.
643+
*false* *true* *null*
644+
In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
645+
for v:null. When converting a boolean to a string "false" and "true" are
646+
used, not "v:false" and "v:true" like in legacy script. "v:none" is not
647+
changed, it is only used in JSON and has no equivalent in other languages.
648648

649649
Indexing a string with [idx] or [idx, idx] uses character indexes instead of
650650
byte indexes. Example: >

src/evalvars.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,8 +2072,8 @@ get_var_special_name(int nr)
20722072
{
20732073
case VVAL_FALSE: return in_vim9script() ? "false" : "v:false";
20742074
case VVAL_TRUE: return in_vim9script() ? "true" : "v:true";
2075+
case VVAL_NULL: return in_vim9script() ? "null" : "v:null";
20752076
case VVAL_NONE: return "v:none";
2076-
case VVAL_NULL: return "v:null";
20772077
}
20782078
internal_error("get_var_special_name()");
20792079
return "42";

src/testdir/test_vim9_expr.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ def Test_expr4_equal()
511511
assert_equal(true, v:none == v:none)
512512
assert_equal(false, v:none == v:null)
513513
assert_equal(true, g:anone == v:none)
514+
assert_equal(true, null == v:null)
515+
assert_equal(true, null == g:anull)
514516
assert_equal(false, v:none == g:anull)
515517

516518
var nr0 = 0
@@ -1063,7 +1065,7 @@ def Test_expr5()
10631065

10641066
assert_equal('atrue', 'a' .. true)
10651067
assert_equal('afalse', 'a' .. false)
1066-
assert_equal('av:null', 'a' .. v:null)
1068+
assert_equal('anull', 'a' .. v:null)
10671069
assert_equal('av:none', 'a' .. v:none)
10681070
if has('float')
10691071
assert_equal('a0.123', 'a' .. 0.123)
@@ -1657,6 +1659,7 @@ def Test_expr7_special()
16571659
assert_equal(false, f)
16581660

16591661
assert_equal(g:special_null, v:null)
1662+
assert_equal(g:special_null, null)
16601663
assert_equal(g:special_none, v:none)
16611664
END
16621665
CheckDefAndScriptSuccess(lines)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2291,
753755
/**/
754756
2290,
755757
/**/

src/vim9compile.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,6 +3967,20 @@ compile_expr7(
39673967
ret = NOTDONE;
39683968
break;
39693969

3970+
/*
3971+
* "null" constant
3972+
*/
3973+
case 'n': if (STRNCMP(*arg, "null", 4) == 0
3974+
&& !eval_isnamec((*arg)[5]))
3975+
{
3976+
*arg += 4;
3977+
rettv->v_type = VAR_SPECIAL;
3978+
rettv->vval.v_number = VVAL_NULL;
3979+
}
3980+
else
3981+
ret = NOTDONE;
3982+
break;
3983+
39703984
/*
39713985
* List: [expr, expr]
39723986
*/
@@ -5006,6 +5020,7 @@ assignment_len(char_u *p, int *heredoc)
50065020
static char *reserved[] = {
50075021
"true",
50085022
"false",
5023+
"null",
50095024
NULL
50105025
};
50115026

0 commit comments

Comments
 (0)