neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 7404c6010dd7abd4339a4ffd6961f2a420fe7ddb
parent 95c862095f54d21737ef12f7da689a037e9a1c3e
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun,  6 Nov 2022 14:50:09 +0800

vim-patch:8.2.3055: strange error for assigning to "x.key" on non-dictionary

Problem:    Strange error for assigning to "x.key" on non-dictionary.
Solution:   Add a specific error message. (closes vim/vim#8451)

https://github.com/vim/vim/commit/3a3b10e87a10dd0bc355618dbfc4a0a6c828aad7

Co-authored-by: Bram Moolenaar <Bram@vim.org>

Diffstat:
Msrc/nvim/eval.c | 10+++++++++-
Msrc/nvim/testdir/test_let.vim | 2+-
Msrc/nvim/testdir/test_listdict.vim | 3+++
3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/nvim/eval.c b/src/nvim/eval.c @@ -66,6 +66,8 @@ static char *e_nowhitespace static char *e_write2 = N_("E80: Error while writing: %s"); static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob required"); static char e_expression_too_recursive_str[] = N_("E1169: Expression too recursive: %s"); +static char e_dot_can_only_be_used_on_dictionary_str[] + = N_("E1203: Dot can only be used on a dictionary: %s"); static char * const namespace_char = "abglstvw"; @@ -1326,7 +1328,13 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const var1.v_type = VAR_UNKNOWN; typval_T var2; var2.v_type = VAR_UNKNOWN; - while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) { + while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.')) { + if (*p == '.' && lp->ll_tv->v_type != VAR_DICT) { + if (!quiet) { + semsg(_(e_dot_can_only_be_used_on_dictionary_str), name); + } + return NULL; + } if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) && !(lp->ll_tv->v_type == VAR_DICT && lp->ll_tv->vval.v_dict != NULL) && !(lp->ll_tv->v_type == VAR_BLOB && lp->ll_tv->vval.v_blob != NULL)) { diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim @@ -276,7 +276,7 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') - call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let {s}.1 = 2', 'E1203:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim @@ -294,6 +294,9 @@ func Test_dict_assign() let d.1 = 1 let d._ = 2 call assert_equal({'1': 1, '_': 2}, d) + + let n = 0 + call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3') endfunc " Function in script-local List or Dict