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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user