From 93a0c2dd63e369528664037b118ff9b9b38a20d4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 8 Sep 2022 08:12:10 +0800 Subject: [PATCH 1/2] vim-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 vim/vim#9247) https://github.com/vim/vim/commit/98cb90ef865089a5ddd20bc0303d449fb7d97fb2 --- src/nvim/eval.c | 17 ++++++++--------- src/nvim/testdir/test_listdict.vim | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0c41381313..1171695be3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2997,7 +2997,9 @@ static int eval7(char **arg, typval_T *rettv, int evaluate, int want_string) // decimal, hex or octal number vim_str2nr(*arg, NULL, &len, STR2NR_ALL, &n, NULL, 0, true); if (len == 0) { - semsg(_(e_invexpr2), *arg); + if (evaluate) { + semsg(_(e_invexpr2), *arg); + } ret = FAIL; break; } @@ -4582,7 +4584,7 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) { typval_T tv; char *key = NULL; - char *start = skipwhite(*arg + 1); + char *curly_expr = skipwhite(*arg + 1); char buf[NUMBUFLEN]; // First check if it's not a curly-braces thing: {expr}. @@ -4590,13 +4592,10 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) // twice. Unfortunately this means we need to call eval1() twice for the // first item. // But {} is an empty Dictionary. - if (*start != '}') { - if (eval1(&start, &tv, false) == FAIL) { // recursive! - return FAIL; - } - if (*skipwhite(start) == '}') { - return NOTDONE; - } + if (*curly_expr != '}' + && eval1(&curly_expr, &tv, false) == OK + && *skipwhite(curly_expr) == '}') { + return NOTDONE; } dict_T *d = NULL; diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 08c415a069..f0440ae14b 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -165,6 +165,9 @@ func Test_dict() call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d) call filter(d, 'v:key =~ ''[ac391]''') call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) + + " allow key starting with number at the start, not a curly expression + call assert_equal({'1foo': 77}, #{1foo: 77}) endfunc " Dictionary identity From 4a67f9d386bb16149eecf32f45a3cb73878f12e7 Mon Sep 17 00:00:00 2001 From: ii14 Date: Wed, 7 Sep 2022 20:45:22 +0200 Subject: [PATCH 2/2] vim-patch:9.0.0409: #{g:x} was seen as a curly-braces expression Problem: #{g:x} was seen as a curly-braces expression. Solution: Do never see #{} as a curly-braces expression. (closes vim/vim#11075) https://github.com/vim/vim/commit/7c7e1e9b98d4e5dbe7358c795a635c6f1f36f418 --- src/nvim/eval.c | 6 ++++-- src/nvim/testdir/test_listdict.vim | 4 ++++ test/functional/ex_cmds/source_spec.lua | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1171695be3..aa2849279e 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4587,12 +4587,14 @@ static int dict_get_tv(char **arg, typval_T *rettv, int evaluate, bool literal) char *curly_expr = skipwhite(*arg + 1); char buf[NUMBUFLEN]; - // First check if it's not a curly-braces thing: {expr}. + // First check if it's not a curly-braces expression: {expr}. // Must do this without evaluating, otherwise a function may be called // twice. Unfortunately this means we need to call eval1() twice for the // first item. - // But {} is an empty Dictionary. + // "{}" is an empty Dictionary. + // "#{abc}" is never a curly-braces expression. if (*curly_expr != '}' + && !literal && eval1(&curly_expr, &tv, false) == OK && *skipwhite(curly_expr) == '}') { return NOTDONE; diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index f0440ae14b..9cef6905a5 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -168,6 +168,10 @@ func Test_dict() " allow key starting with number at the start, not a curly expression call assert_equal({'1foo': 77}, #{1foo: 77}) + + " #{expr} is not a curly expression + let x = 'x' + call assert_equal(#{g: x}, #{g:x}) endfunc " Dictionary identity diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index cd1f43f9fd..10ebefd8cd 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -104,7 +104,7 @@ describe(':source', function() eq("0zBEEFCAFE", meths.exec('echo d', true)) exec('set cpoptions+=C') - eq('Vim(let):E15: Invalid expression: #{', exc_exec('source')) + eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) end) it('selection in current buffer', function() @@ -138,7 +138,7 @@ describe(':source', function() eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()')) exec('set cpoptions+=C') - eq('Vim(let):E15: Invalid expression: #{', exc_exec("'<,'>source")) + eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec("'<,'>source")) end) it('does not break if current buffer is modified while sourced', function()