]> granicus.if.org Git - vim/commitdiff
patch 8.2.3702: first key in dict is seen as curly expression and fails v8.2.3702
authorBram Moolenaar <Bram@vim.org>
Tue, 30 Nov 2021 11:56:22 +0000 (11:56 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 30 Nov 2021 11:56:22 +0000 (11:56 +0000)
Problem:    First key in dict is seen as curly expression and fails.
Solution:   Ignore failure of curly expression. (closes #9247)

src/dict.c
src/testdir/test_listdict.vim
src/typval.c
src/version.c

index 032c1b5a81403260c26c53ec61e90fd67e98da05..98be26310b71e1c5cd1e8240d3867c1b6ea6b647 100644 (file)
@@ -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)
     {
index 0b024a0f6f2d192c3de05f5502cf3f2bc9cabc82..10cb78662236ac63adc5441b02701366d12c977a 100644 (file)
@@ -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
index c859122ee793367e7b9351c9ed349ed08018b617..fb945cb135caefc306552a20bc4668a7ebfdad8e 100644 (file)
@@ -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;
index b8dbf37b57ffc5404e862705bfd33c4d6799412b..302db8e0b3361dc0f97004d569bfe0b43f5dec79 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3702,
 /**/
     3701,
 /**/