Patch 8.2.2168
Problem: Vim9: error for assigning to dict of dict.
Solution: Remember the destination type. (closes #7506)
Files: src/vim9compile.c, src/testdir/test_vim9_assign.vim
*** ../vim-8.2.2167/src/vim9compile.c 2020-12-19 16:30:39.439810130 +0100
--- src/vim9compile.c 2020-12-20 15:15:44.731796102 +0100
***************
*** 5876,5882 ****
if (has_index)
{
! int r;
// Compile the "idx" in "var[idx]" or "key" in "var.key".
p = var_start + varlen;
--- 5876,5883 ----
if (has_index)
{
! int r;
! vartype_T dest_type;
// Compile the "idx" in "var[idx]" or "key" in "var.key".
p = var_start + varlen;
***************
*** 5913,5922 ****
else
type = &t_dict_any;
}
! if (type->tt_type == VAR_DICT
&& may_generate_2STRING(-1, cctx) == FAIL)
goto theend;
! if (type->tt_type == VAR_LIST
&& ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
!= VAR_NUMBER)
{
--- 5914,5924 ----
else
type = &t_dict_any;
}
! dest_type = type->tt_type;
! if (dest_type == VAR_DICT
&& may_generate_2STRING(-1, cctx) == FAIL)
goto theend;
! if (dest_type == VAR_LIST
&& ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
!= VAR_NUMBER)
{
***************
*** 5954,5965 ****
else
generate_loadvar(cctx, dest, name, lvar, type);
! if (type->tt_type == VAR_LIST)
{
if (generate_instr_drop(cctx, ISN_STORELIST, 3) == FAIL)
goto theend;
}
! else if (type->tt_type == VAR_DICT)
{
if (generate_instr_drop(cctx, ISN_STOREDICT, 3) == FAIL)
goto theend;
--- 5956,5967 ----
else
generate_loadvar(cctx, dest, name, lvar, type);
! if (dest_type == VAR_LIST)
{
if (generate_instr_drop(cctx, ISN_STORELIST, 3) == FAIL)
goto theend;
}
! else if (dest_type == VAR_DICT)
{
if (generate_instr_drop(cctx, ISN_STOREDICT, 3) == FAIL)
goto theend;
*** ../vim-8.2.2167/src/testdir/test_vim9_assign.vim 2020-12-20
14:49:38.763472067 +0100
--- src/testdir/test_vim9_assign.vim 2020-12-20 15:19:59.834929750 +0100
***************
*** 560,565 ****
--- 560,571 ----
dict3.key = 'yet another'
assert_equal(dict3, {key: 'yet another'})
+ # member "any" can also be a dict and assigned to
+ var anydict: dict<any> = {nest: {}, nr: 0}
+ anydict.nest['this'] = 123
+ anydict.nest.that = 456
+ assert_equal({nest: {this: 123, that: 456}, nr: 0}, anydict)
+
var lines =<< trim END
vim9script
var dd = {}
*** ../vim-8.2.2167/src/version.c 2020-12-20 14:49:38.763472067 +0100
--- src/version.c 2020-12-20 15:16:41.327555058 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2168,
/**/
--
Our job was to build a computer information system for the branch banks. We
were the perfect people for the job: Dean had seen a computer once, and I had
heard Dean talk about it.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202012201421.0BKELKSN1902588%40masaka.moolenaar.net.