# HG changeset patch # User Bram Moolenaar # Date 1608474604 -3600 # Node ID ac934fbacc0e0d90a7f383c46355d3578fa200e5 # Parent 78fd1e45c2fd4bcc2c2162741a86caea44d5ae49 patch 8.2.2168: Vim9: error for assigning to dict of dict Commit: https://github.com/vim/vim/commit/d24602f43cf1f3c37136fe275b83153c26a406e7 Author: Bram Moolenaar Date: Sun Dec 20 15:20:56 2020 +0100 patch 8.2.2168: Vim9: error for assigning to dict of dict Problem: Vim9: error for assigning to dict of dict. Solution: Remember the destination type. (closes https://github.com/vim/vim/issues/7506) diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -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 = {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 = {} diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2168, +/**/ 2167, /**/ 2166, diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -5876,7 +5876,8 @@ compile_assignment(char_u *arg, exarg_T 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 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 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;