summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-04 19:12:14 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-04 19:12:14 +0100
commitc5e6a7179d7dee4315b412b56e172bb1ff092d3e (patch)
tree70eae554a7a7cb493df307f92b1f0372033132bf /src/vim9compile.c
parent6cd42db9dc1251b052b97d47bafc063eacac1b3e (diff)
downloadvim-git-8.2.2090.tar.gz
patch 8.2.2090: Vim9: dict does not accept a key in quotesv8.2.2090
Problem: Vim9: dict does not accept a key in quotes. Solution: Recognize a key in single or double quotes.
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 4b8a8ad71..2cd4b52c0 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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)