Mercurial > vim
changeset 26329:8afd7aa25ab6
patch 8.2.3695: confusing error for missing key
Commit: https://github.com/vim/vim/commit/5c1ec439f0a69e9aa7ece9bbb7d916f48f58be1e
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 29 13:44:55 2021 +0000
patch 8.2.3695: confusing error for missing key
Problem: Confusing error for missing key.
Solution: Use the actualy key for the error. (closes https://github.com/vim/vim/issues/9241)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 29 Nov 2021 14:45:04 +0100 |
parents | 4ada663d2db6 |
children | 55e658312376 |
files | src/eval.c src/testdir/test_listdict.vim src/version.c |
diffstat | 3 files changed, 31 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -4287,12 +4287,18 @@ eval_index_inner( return FAIL; } - item = dict_find(rettv->vval.v_dict, key, (int)keylen); - - if (item == NULL && verbose) - semsg(_(e_dictkey), key); + item = dict_find(rettv->vval.v_dict, key, keylen); + if (item == NULL) + { + if (verbose) + { + if (keylen > 0) + key[keylen] = NUL; + semsg(_(e_dictkey), key); + } return FAIL; + } copy_tv(&item->di_tv, &tmp); clear_tv(rettv);
--- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -455,6 +455,25 @@ func Test_dict_func_remove() call CheckLegacyAndVim9Failure(lines, 'E716:') let lines =<< trim END + let d = {'a-b': 55} + echo d.a-b + END + call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"') + + let lines =<< trim END + vim9script + var d = {'a-b': 55} + echo d.a-b + END + call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"') + + let lines =<< trim END + var d = {'a-b': 55} + echo d.a-b + END + call CheckDefFailure(lines, 'E1004: White space required before and after ''-''') + + let lines =<< trim END let d = {1: 'a', 3: 'c'} call remove(d, []) END