Problem: Cannot use empty dictionary key, even though it can be useful.
Solution: Allow using an empty dictionary key.
if (len == -1)
{
/* "[key]": get key from "var1" */
- key = get_tv_string(&var1); /* is number or string */
- if (*key == NUL)
+ key = get_tv_string_chk(&var1); /* is number or string */
+ if (key == NULL)
{
- if (!quiet)
- EMSG(_(e_emptykey));
clear_tv(&var1);
return NULL;
}
if (len == -1)
{
- key = get_tv_string(&var1);
- if (*key == NUL)
+ key = get_tv_string_chk(&var1);
+ if (key == NULL)
{
- if (verbose)
- EMSG(_(e_emptykey));
clear_tv(&var1);
return FAIL;
}
if (evaluate)
{
key = get_tv_string_buf_chk(&tvkey, buf);
- if (key == NULL || *key == NUL)
+ if (key == NULL)
{
/* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */
- if (key != NULL)
- EMSG(_(e_emptykey));
clear_tv(&tvkey);
goto failret;
}
char_u *p;
if ((hash = *key) == 0)
- return (hash_T)0; /* Empty keys are not allowed, but we don't
- want to crash if we get one. */
+ return (hash_T)0;
p = key + 1;
/* A simplistic algorithm that appears to do very well.
call assert_false(has('patch-9.1.0'))
call assert_false(has('patch-9.9.1'))
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1707,
/**/
1706,
/**/