Patch 8.2.4589
Problem: Cannot index the g: dictionary.
Solution: Recognize using "g:[key]". (closes #9969)
Files: src/ex_docmd.c, src/eval.c, src/vim9compile.c,
src/testdir/test_vim9_assign.vim
*** ../vim-8.2.4588/src/ex_docmd.c 2022-03-05 20:24:36.895308699 +0000
--- src/ex_docmd.c 2022-03-18 17:54:28.449369074 +0000
***************
*** 3523,3534 ****
return eap->cmd;
}
! if (p != eap->cmd && (
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
! || (*p == '.' && (ASCII_ISALPHA(p[1])
! || p[1] == '_'))))
{
char_u *after = eap->cmd;
--- 3523,3536 ----
return eap->cmd;
}
! if ((p != eap->cmd && (
// "varname[]" is an expression.
*p == '['
// "varname.key" is an expression.
! || (*p == '.'
! && (ASCII_ISALPHA(p[1]) || p[1] == '_'))))
! // g:[key] is an expression
! || STRNCMP(eap->cmd, "g:[", 3) == 0)
{
char_u *after = eap->cmd;
*** ../vim-8.2.4588/src/eval.c 2022-03-17 11:46:51.651820164 +0000
--- src/eval.c 2022-03-18 18:33:06.664876574 +0000
***************
*** 929,935 ****
if (vim9script)
{
// "a: type" is declaring variable "a" with a type, not "a:".
! if (p == name + 2 && p[-1] == ':')
{
--p;
lp->ll_name_end = p;
--- 929,936 ----
if (vim9script)
{
// "a: type" is declaring variable "a" with a type, not "a:".
! // However, "g:[key]" is indexing a dictionary.
! if (p == name + 2 && p[-1] == ':' && *p != '[')
{
--p;
lp->ll_name_end = p;
*** ../vim-8.2.4588/src/vim9compile.c 2022-03-15 19:29:26.542954696 +0000
--- src/vim9compile.c 2022-03-18 19:22:32.123950961 +0000
***************
*** 1000,1006 ****
break;
case dest_global:
if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
! generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
else
generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
break;
--- 1000,1011 ----
break;
case dest_global:
if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
! {
! 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;
***************
*** 2413,2429 ****
// Recognize an assignment if we recognize the variable
// name:
// "g:var = 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] == ':')
|| variable_exists(eap->cmd, len, cctx))
{
*line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
--- 2418,2436 ----
// 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
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);
*** ../vim-8.2.4588/src/testdir/test_vim9_assign.vim 2022-03-12 21:28:18.528257721 +0000
--- src/testdir/test_vim9_assign.vim 2022-03-18 19:32:32.549718683 +0000
***************
*** 1117,1122 ****
--- 1117,1130 ----
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
+ var key = 'foo'
+ g:[key] = 'value'
+ assert_equal('value', g:foo)
+ unlet g:foo
+ END
+ v9.CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
var dd = {one: 1}
dd.one) = 2
END
*** ../vim-8.2.4588/src/version.c 2022-03-18 15:41:13.366489671 +0000
--- src/version.c 2022-03-18 19:43:56.219263048 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4589,
/**/
--
GALAHAD turns back. We see from his POV the lovely ZOOT standing by him
smiling enchantingly and a number of equally delectable GIRLIES draped
around in the seductively poulticed room. They look at him smilingly and
wave.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///