mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
vim-patch:8.2.3702: first key in dict is seen as curly expression and fails
Problem: First key in dict is seen as curly expression and fails.
Solution: Ignore failure of curly expression. (closes vim/vim#9247)
98cb90ef86
This commit is contained in:
@@ -2997,7 +2997,9 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string)
|
|||||||
// decimal, hex or octal number
|
// decimal, hex or octal number
|
||||||
vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0, true);
|
vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0, true);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
|
if (evaluate) {
|
||||||
semsg(_(e_invexpr2), *arg);
|
semsg(_(e_invexpr2), *arg);
|
||||||
|
}
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4582,7 +4584,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal)
|
|||||||
{
|
{
|
||||||
typval_T tv;
|
typval_T tv;
|
||||||
char *key = NULL;
|
char *key = NULL;
|
||||||
char *start = skipwhite(*arg + 1);
|
char *curly_expr = skipwhite(*arg + 1);
|
||||||
char buf[NUMBUFLEN];
|
char buf[NUMBUFLEN];
|
||||||
|
|
||||||
// First check if it's not a curly-braces thing: {expr}.
|
// First check if it's not a curly-braces thing: {expr}.
|
||||||
@@ -4590,14 +4592,11 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal)
|
|||||||
// twice. Unfortunately this means we need to call eval1() twice for the
|
// twice. Unfortunately this means we need to call eval1() twice for the
|
||||||
// first item.
|
// first item.
|
||||||
// But {} is an empty Dictionary.
|
// But {} is an empty Dictionary.
|
||||||
if (*start != '}') {
|
if (*curly_expr != '}'
|
||||||
if (eval1(&start, &tv, false) == FAIL) { // recursive!
|
&& eval1(&curly_expr, &tv, false) == OK
|
||||||
return FAIL;
|
&& *skipwhite(curly_expr) == '}') {
|
||||||
}
|
|
||||||
if (*skipwhite(start) == '}') {
|
|
||||||
return NOTDONE;
|
return NOTDONE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
dict_T *d = NULL;
|
dict_T *d = NULL;
|
||||||
if (evaluate) {
|
if (evaluate) {
|
||||||
|
@@ -165,6 +165,9 @@ func Test_dict()
|
|||||||
call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
|
call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
|
||||||
call filter(d, 'v:key =~ ''[ac391]''')
|
call filter(d, 'v:key =~ ''[ac391]''')
|
||||||
call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d)
|
call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d)
|
||||||
|
|
||||||
|
" allow key starting with number at the start, not a curly expression
|
||||||
|
call assert_equal({'1foo': 77}, #{1foo: 77})
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Dictionary identity
|
" Dictionary identity
|
||||||
|
Reference in New Issue
Block a user