forked from aniani/vim
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)
This commit is contained in:
@@ -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
|
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()|
|
Simple types are string, float, special and bool. For other types |string()|
|
||||||
can be used.
|
can be used.
|
||||||
*false* *true*
|
*false* *true* *null*
|
||||||
In Vim9 script one can use "true" for v:true and "false" for v:false. When
|
In Vim9 script one can use "true" for v:true, "false" for v:false and "null"
|
||||||
converting a boolean to a string "false" and "true" are used, not "v:false"
|
for v:null. When converting a boolean to a string "false" and "true" are
|
||||||
and "v:true" like in legacy script. "v:none" and "v:null" are not changed,
|
used, not "v:false" and "v:true" like in legacy script. "v:none" is not
|
||||||
they are only used in JSON.
|
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
|
Indexing a string with [idx] or [idx, idx] uses character indexes instead of
|
||||||
byte indexes. Example: >
|
byte indexes. Example: >
|
||||||
|
@@ -2072,8 +2072,8 @@ get_var_special_name(int nr)
|
|||||||
{
|
{
|
||||||
case VVAL_FALSE: return in_vim9script() ? "false" : "v:false";
|
case VVAL_FALSE: return in_vim9script() ? "false" : "v:false";
|
||||||
case VVAL_TRUE: return in_vim9script() ? "true" : "v:true";
|
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_NONE: return "v:none";
|
||||||
case VVAL_NULL: return "v:null";
|
|
||||||
}
|
}
|
||||||
internal_error("get_var_special_name()");
|
internal_error("get_var_special_name()");
|
||||||
return "42";
|
return "42";
|
||||||
|
@@ -511,6 +511,8 @@ def Test_expr4_equal()
|
|||||||
assert_equal(true, v:none == v:none)
|
assert_equal(true, v:none == v:none)
|
||||||
assert_equal(false, v:none == v:null)
|
assert_equal(false, v:none == v:null)
|
||||||
assert_equal(true, g:anone == v:none)
|
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)
|
assert_equal(false, v:none == g:anull)
|
||||||
|
|
||||||
var nr0 = 0
|
var nr0 = 0
|
||||||
@@ -1063,7 +1065,7 @@ def Test_expr5()
|
|||||||
|
|
||||||
assert_equal('atrue', 'a' .. true)
|
assert_equal('atrue', 'a' .. true)
|
||||||
assert_equal('afalse', 'a' .. false)
|
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)
|
assert_equal('av:none', 'a' .. v:none)
|
||||||
if has('float')
|
if has('float')
|
||||||
assert_equal('a0.123', 'a' .. 0.123)
|
assert_equal('a0.123', 'a' .. 0.123)
|
||||||
@@ -1657,6 +1659,7 @@ def Test_expr7_special()
|
|||||||
assert_equal(false, f)
|
assert_equal(false, f)
|
||||||
|
|
||||||
assert_equal(g:special_null, v:null)
|
assert_equal(g:special_null, v:null)
|
||||||
|
assert_equal(g:special_null, null)
|
||||||
assert_equal(g:special_none, v:none)
|
assert_equal(g:special_none, v:none)
|
||||||
END
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2291,
|
||||||
/**/
|
/**/
|
||||||
2290,
|
2290,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -3967,6 +3967,20 @@ compile_expr7(
|
|||||||
ret = NOTDONE;
|
ret = NOTDONE;
|
||||||
break;
|
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]
|
* List: [expr, expr]
|
||||||
*/
|
*/
|
||||||
@@ -5006,6 +5020,7 @@ assignment_len(char_u *p, int *heredoc)
|
|||||||
static char *reserved[] = {
|
static char *reserved[] = {
|
||||||
"true",
|
"true",
|
||||||
"false",
|
"false",
|
||||||
|
"null",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user