From 98cb90ef865089a5ddd20bc0303d449fb7d97fb2 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 30 Nov 2021 11:56:22 +0000 Subject: 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) --- src/dict.c | 14 ++++++-------- src/testdir/test_listdict.vim | 3 +++ src/typval.c | 3 ++- src/version.c | 2 ++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/dict.c b/src/dict.c index 032c1b5a8..98be26310 100644 --- a/src/dict.c +++ b/src/dict.c @@ -891,7 +891,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal) typval_T tv; char_u *key = NULL; dictitem_T *item; - char_u *start = skipwhite(*arg + 1); + char_u *curly_expr = skipwhite(*arg + 1); char_u buf[NUMBUFLEN]; int vim9script = in_vim9script(); int had_comma; @@ -903,13 +903,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal) * first item. * But {} is an empty Dictionary. */ - if (!vim9script && *start != '}') - { - if (eval1(&start, &tv, NULL) == FAIL) // recursive! - return FAIL; - if (*skipwhite(start) == '}') - return NOTDONE; - } + if (!vim9script + && *curly_expr != '}' + && eval1(&curly_expr, &tv, NULL) == OK + && *skipwhite(curly_expr) == '}') + return NOTDONE; if (evaluate) { diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim index 0b024a0f6..10cb78662 100644 --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -297,6 +297,9 @@ func Test_dict() call assert_fails('let d={[] : 10}', 'E730:') " undefined variable as value 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 " This was allowed in legacy Vim script diff --git a/src/typval.c b/src/typval.c index c859122ee..fb945cb13 100644 --- a/src/typval.c +++ b/src/typval.c @@ -1822,7 +1822,8 @@ eval_number( : STR2NR_ALL, &n, NULL, 0, TRUE); if (len == 0) { - semsg(_(e_invalid_expression_str), *arg); + if (evaluate) + semsg(_(e_invalid_expression_str), *arg); return FAIL; } *arg += len; diff --git a/src/version.c b/src/version.c index b8dbf37b5..302db8e0b 100644 --- a/src/version.c +++ b/src/version.c @@ -753,6 +753,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 3702, /**/ 3701, /**/ -- cgit v1.2.1