1
0
forked from aniani/vim

patch 8.2.2090: Vim9: dict does not accept a key in quotes

Problem:    Vim9: dict does not accept a key in quotes.
Solution:   Recognize a key in single or double quotes.
This commit is contained in:
Bram Moolenaar
2020-12-04 19:12:14 +01:00
parent 6cd42db9dc
commit c5e6a7179d
6 changed files with 83 additions and 29 deletions

View File

@@ -3024,26 +3024,11 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
if (**arg == '}')
break;
// {name: value} uses "name" as a literal key and
// {[expr]: value} uses an evaluated key.
if (**arg != '[')
{
char_u *end = skip_literal_key(*arg);
if (end == *arg)
{
semsg(_(e_invalid_key_str), *arg);
return FAIL;
}
key = vim_strnsave(*arg, end - *arg);
if (generate_PUSHS(cctx, key) == FAIL)
return FAIL;
*arg = end;
}
else
if (**arg == '[')
{
isn_T *isn;
// {[expr]: value} uses an evaluated key.
*arg = skipwhite(*arg + 1);
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
@@ -3066,6 +3051,17 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
}
++*arg;
}
else
{
// {"name": value},
// {'name': value},
// {name: value} use "name" as a literal key
key = get_literal_key(arg);
if (key == NULL)
return FAIL;
if (generate_PUSHS(cctx, key) == FAIL)
return FAIL;
}
// Check for duplicate keys, if using string keys.
if (key != NULL)