Skip to content

Commit 98cb90e

Browse files
committed
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)
1 parent c750d91 commit 98cb90e

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/dict.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
891891
typval_T tv;
892892
char_u *key = NULL;
893893
dictitem_T *item;
894-
char_u *start = skipwhite(*arg + 1);
894+
char_u *curly_expr = skipwhite(*arg + 1);
895895
char_u buf[NUMBUFLEN];
896896
int vim9script = in_vim9script();
897897
int had_comma;
@@ -903,13 +903,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
903903
* first item.
904904
* But {} is an empty Dictionary.
905905
*/
906-
if (!vim9script && *start != '}')
907-
{
908-
if (eval1(&start, &tv, NULL) == FAIL) // recursive!
909-
return FAIL;
910-
if (*skipwhite(start) == '}')
911-
return NOTDONE;
912-
}
906+
if (!vim9script
907+
&& *curly_expr != '}'
908+
&& eval1(&curly_expr, &tv, NULL) == OK
909+
&& *skipwhite(curly_expr) == '}')
910+
return NOTDONE;
913911

914912
if (evaluate)
915913
{

src/testdir/test_listdict.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ func Test_dict()
297297
call assert_fails('let d={[] : 10}', 'E730:')
298298
" undefined variable as value
299299
call assert_fails("let d={'k' : i}", 'E121:')
300+
301+
" allow key starting with number at the start, not a curly expression
302+
call assert_equal({'1foo': 77}, #{1foo: 77})
300303
endfunc
301304

302305
" This was allowed in legacy Vim script

src/typval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,8 @@ eval_number(
18221822
: STR2NR_ALL, &n, NULL, 0, TRUE);
18231823
if (len == 0)
18241824
{
1825-
semsg(_(e_invalid_expression_str), *arg);
1825+
if (evaluate)
1826+
semsg(_(e_invalid_expression_str), *arg);
18261827
return FAIL;
18271828
}
18281829
*arg += len;

src/version.c

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

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
3702,
756758
/**/
757759
3701,
758760
/**/

0 commit comments

Comments
 (0)