To: vim_dev@googlegroups.com Subject: Patch 8.2.1339 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1339 Problem: Vim9: assigning to global dict variable doesn't work. Solution: Guess variable type based in index type. (issue #6591) Files: src/vim9compile.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1338/src/vim9compile.c 2020-08-01 15:38:33.941599081 +0200 --- src/vim9compile.c 2020-08-01 15:51:29.538189640 +0200 *************** *** 5486,5496 **** { has_index = TRUE; if (type->tt_member == NULL) ! { ! semsg(_("E1088: cannot use an index on %s"), name); ! goto theend; ! } ! member_type = type->tt_member; } else { --- 5486,5494 ---- { has_index = TRUE; if (type->tt_member == NULL) ! member_type = &t_any; ! else ! member_type = type->tt_member; } else { *************** *** 5719,5724 **** --- 5717,5734 ---- emsg(_(e_missbrac)); goto theend; } + if (type == &t_any) + { + type_T *idx_type = ((type_T **)stack->ga_data)[ + stack->ga_len - 1]; + // Index on variable of unknown type: guess the type from the + // index type: number is dict, otherwise dict. + // TODO: should do the assignment at runtime + if (idx_type->tt_type == VAR_NUMBER) + type = &t_list_any; + else + type = &t_dict_any; + } if (type->tt_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL) goto theend; *** ../vim-8.2.1338/src/testdir/test_vim9_script.vim 2020-08-01 15:38:33.941599081 +0200 --- src/testdir/test_vim9_script.vim 2020-08-01 15:50:36.318423238 +0200 *************** *** 274,279 **** --- 274,303 ---- FillDict() END call CheckScriptFailure(lines, 'E1103:') + + # assignment to global dict + lines =<< trim END + vim9script + g:test = {} + def FillDict(): dict + g:test['a'] = 43 + return g:test + enddef + assert_equal(#{a: 43}, FillDict()) + END + call CheckScriptSuccess(lines) + + # assignment to buffer dict + lines =<< trim END + vim9script + b:test = {} + def FillDict(): dict + b:test['a'] = 43 + return b:test + enddef + assert_equal(#{a: 43}, FillDict()) + END + call CheckScriptSuccess(lines) enddef def Test_assignment_local() *** ../vim-8.2.1338/src/version.c 2020-08-01 15:38:33.941599081 +0200 --- src/version.c 2020-08-01 15:50:52.034354258 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1339, /**/ -- hundred-and-one symptoms of being an internet addict: 93. New mail alarm on your palmtop annoys other churchgoers. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///