if (vim9script)
{
// "a: type" is declaring variable "a" with a type, not "a:".
- if (p == name + 2 && p[-1] == ':')
+ // However, "g:[key]" is indexing a dictionary.
+ if (p == name + 2 && p[-1] == ':' && *p != '[')
{
--p;
lp->ll_name_end = p;
return eap->cmd;
}
- if (p != eap->cmd && (
+ if ((p != eap->cmd && (
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
- || (*p == '.' && (ASCII_ISALPHA(p[1])
- || p[1] == '_'))))
+ || (*p == '.'
+ && (ASCII_ISALPHA(p[1]) || p[1] == '_'))))
+ // g:[key] is an expression
+ || STRNCMP(eap->cmd, "g:[", 3) == 0)
{
char_u *after = eap->cmd;
break;
case dest_global:
if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
- generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
+ {
+ if (name[2] == NUL)
+ generate_instr_type(cctx, ISN_LOADGDICT, &t_dict_any);
+ else
+ generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
+ }
else
generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
break;
// Recognize an assignment if we recognize the variable
// name:
+ // "&opt = expr"
+ // "$ENV = expr"
+ // "@r = expr"
// "g:var = expr"
+ // "g:[key] = expr"
// "local = expr" where "local" is a local var.
// "script = expr" where "script" is a script-local var.
// "import = expr" where "import" is an imported var
- // "&opt = expr"
- // "$ENV = expr"
- // "@r = expr"
if (*eap->cmd == '&'
|| *eap->cmd == '$'
|| *eap->cmd == '@'
|| ((len) > 2 && eap->cmd[1] == ':')
+ || STRNCMP(eap->cmd, "g:[", 3) == 0
|| variable_exists(eap->cmd, len, cctx))
{
*line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);