]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2168: Vim9: error for assigning to dict of dict v8.2.2168
authorBram Moolenaar <Bram@vim.org>
Sun, 20 Dec 2020 14:20:56 +0000 (15:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 20 Dec 2020 14:20:56 +0000 (15:20 +0100)
Problem:    Vim9: error for assigning to dict of dict.
Solution:   Remember the destination type. (closes #7506)

src/testdir/test_vim9_assign.vim
src/version.c
src/vim9compile.c

index 4a6f1a7e5cb2f06e1b2bb4bd659787c639be88f6..7954aa128ed66e5540fbeaa18e13ff83890fae6c 100644 (file)
@@ -560,6 +560,12 @@ def Test_assignment_dict()
   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 = {}
index 88889b8114f3322c418e2625f18255a936fb46f9..67cc9045bf56e3bc3daa9eab36a0efac64218548 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2168,
 /**/
     2167,
 /**/
index c584918801dde2c1fcb3a206573332ce1bbe9f0c..9bd36981af2d2ecb1f127c600b01e579647bdeb2 100644 (file)
@@ -5876,7 +5876,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
 
        if (has_index)
        {
-           int r;
+           int         r;
+           vartype_T   dest_type;
 
            // Compile the "idx" in "var[idx]" or "key" in "var.key".
            p = var_start + varlen;
@@ -5913,10 +5914,11 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                else
                    type = &t_dict_any;
            }
-           if (type->tt_type == VAR_DICT
+           dest_type = type->tt_type;
+           if (dest_type == VAR_DICT
                    && may_generate_2STRING(-1, cctx) == FAIL)
                goto theend;
-           if (type->tt_type == VAR_LIST
+           if (dest_type == VAR_LIST
                    && ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
                                                                 != VAR_NUMBER)
            {
@@ -5954,12 +5956,12 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
            else
                generate_loadvar(cctx, dest, name, lvar, type);
 
-           if (type->tt_type == VAR_LIST)
+           if (dest_type == VAR_LIST)
            {
                if (generate_instr_drop(cctx, ISN_STORELIST, 3) == FAIL)
                    goto theend;
            }
-           else if (type->tt_type == VAR_DICT)
+           else if (dest_type == VAR_DICT)
            {
                if (generate_instr_drop(cctx, ISN_STOREDICT, 3) == FAIL)
                    goto theend;