diff options
author | Michael Ennen <mike.ennen@gmail.com> | 2016-11-24 23:45:05 -0700 |
---|---|---|
committer | Michael Ennen <mike.ennen@gmail.com> | 2016-11-25 18:23:11 -0700 |
commit | 8f84c1da83a2ef0912325f48b23637c706f3f2f0 (patch) | |
tree | c6b1eda7b44aed43e466596795f90fa7b8fa8d22 /src | |
parent | 5f0260808cf3712718555ee177476b8aefd78280 (diff) | |
download | rneovim-8f84c1da83a2ef0912325f48b23637c706f3f2f0.tar.gz rneovim-8f84c1da83a2ef0912325f48b23637c706f3f2f0.tar.bz2 rneovim-8f84c1da83a2ef0912325f48b23637c706f3f2f0.zip |
vim-patch:7.4.1707
Problem: Cannot use empty dictionary key, even though it can be useful.
Solution: Allow using an empty dictionary key.
https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 20 | ||||
-rw-r--r-- | src/nvim/hashtab.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_expr.vim | 14 | ||||
-rw-r--r-- | src/nvim/version.c | 2 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 750ef4f94f..d7188290f2 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2145,11 +2145,9 @@ get_lval ( if (lp->ll_tv->v_type == VAR_DICT) { if (len == -1) { - /* "[key]": get key from "var1" */ - key = get_tv_string(&var1); /* is number or string */ - if (*key == NUL) { - if (!quiet) - EMSG(_(e_emptykey)); + // "[key]": get key from "var1" + key = get_tv_string_chk(&var1); // is number or string + if (key == NULL) { clear_tv(&var1); return NULL; } @@ -4600,10 +4598,8 @@ eval_index ( dictitem_T *item; if (len == -1) { - key = get_tv_string(&var1); - if (*key == NUL) { - if (verbose) - EMSG(_(e_emptykey)); + key = get_tv_string_chk(&var1); + if (key == NULL) { clear_tv(&var1); return FAIL; } @@ -6587,10 +6583,8 @@ static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate) } if (evaluate) { key = get_tv_string_buf_chk(&tvkey, buf); - if (key == NULL || *key == NUL) { - /* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */ - if (key != NULL) - EMSG(_(e_emptykey)); + if (key == NULL) { + // "key" is NULL when get_tv_string_buf_chk() gave an errmsg clear_tv(&tvkey); goto failret; } diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 7d4ae61fc4..fa4077f22f 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -368,8 +368,7 @@ hash_T hash_hash(char_u *key) hash_T hash = *key; if (hash == 0) { - // Empty keys are not allowed, but we don't want to crash if we get one. - return (hash_T) 0; + return (hash_T)0; } // A simplistic algorithm that appears to do very well. diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 7ea4ebc7df..51d6a0931c 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -23,3 +23,17 @@ func Test_strcharpart() call assert_equal('a', strcharpart('axb', -1, 2)) endfunc + +func Test_dict() + let d = {'': 'empty', 'a': 'a', 0: 'zero'} + call assert_equal('empty', d['']) + call assert_equal('a', d['a']) + call assert_equal('zero', d[0]) + call assert_true(has_key(d, '')) + call assert_true(has_key(d, 'a')) + + let d[''] = 'none' + let d['a'] = 'aaa' + call assert_equal('none', d['']) + call assert_equal('aaa', d['a']) +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 8f3619f1e8..e7ab593285 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -737,7 +737,7 @@ static int included_patches[] = { // 1710, // 1709 NA // 1708, - // 1707, + 1707, // 1706 NA // 1705 NA 1704, |