Mercurial > vim
changeset 26342:936f77929f16 v8.2.3702
patch 8.2.3702: first key in dict is seen as curly expression and fails
Commit: https://github.com/vim/vim/commit/98cb90ef865089a5ddd20bc0303d449fb7d97fb2
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 30 11:56:22 2021 +0000
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 https://github.com/vim/vim/issues/9247)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 30 Nov 2021 13:00:06 +0100 |
parents | b9b685b5f8ae |
children | b50663eefd00 |
files | src/dict.c src/testdir/test_listdict.vim src/typval.c src/version.c |
diffstat | 4 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dict.c +++ b/src/dict.c @@ -891,7 +891,7 @@ eval_dict(char_u **arg, typval_T *rettv, 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, * 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) {
--- 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