mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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 #9247)
This commit is contained in:
12
src/dict.c
12
src/dict.c
@@ -891,7 +891,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
|
|||||||
typval_T tv;
|
typval_T tv;
|
||||||
char_u *key = NULL;
|
char_u *key = NULL;
|
||||||
dictitem_T *item;
|
dictitem_T *item;
|
||||||
char_u *start = skipwhite(*arg + 1);
|
char_u *curly_expr = skipwhite(*arg + 1);
|
||||||
char_u buf[NUMBUFLEN];
|
char_u buf[NUMBUFLEN];
|
||||||
int vim9script = in_vim9script();
|
int vim9script = in_vim9script();
|
||||||
int had_comma;
|
int had_comma;
|
||||||
@@ -903,13 +903,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
|
|||||||
* first item.
|
* first item.
|
||||||
* But {} is an empty Dictionary.
|
* But {} is an empty Dictionary.
|
||||||
*/
|
*/
|
||||||
if (!vim9script && *start != '}')
|
if (!vim9script
|
||||||
{
|
&& *curly_expr != '}'
|
||||||
if (eval1(&start, &tv, NULL) == FAIL) // recursive!
|
&& eval1(&curly_expr, &tv, NULL) == OK
|
||||||
return FAIL;
|
&& *skipwhite(curly_expr) == '}')
|
||||||
if (*skipwhite(start) == '}')
|
|
||||||
return NOTDONE;
|
return NOTDONE;
|
||||||
}
|
|
||||||
|
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
{
|
{
|
||||||
|
@@ -297,6 +297,9 @@ func Test_dict()
|
|||||||
call assert_fails('let d={[] : 10}', 'E730:')
|
call assert_fails('let d={[] : 10}', 'E730:')
|
||||||
" undefined variable as value
|
" undefined variable as value
|
||||||
call assert_fails("let d={'k' : i}", 'E121:')
|
call assert_fails("let d={'k' : i}", 'E121:')
|
||||||
|
|
||||||
|
" allow key starting with number at the start, not a curly expression
|
||||||
|
call assert_equal({'1foo': 77}, #{1foo: 77})
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" This was allowed in legacy Vim script
|
" This was allowed in legacy Vim script
|
||||||
|
@@ -1822,6 +1822,7 @@ eval_number(
|
|||||||
: STR2NR_ALL, &n, NULL, 0, TRUE);
|
: STR2NR_ALL, &n, NULL, 0, TRUE);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
|
if (evaluate)
|
||||||
semsg(_(e_invalid_expression_str), *arg);
|
semsg(_(e_invalid_expression_str), *arg);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@@ -753,6 +753,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 */
|
||||||
|
/**/
|
||||||
|
3702,
|
||||||
/**/
|
/**/
|
||||||
3701,
|
3701,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user