Mercurial > vim
changeset 21168:f26a606e6dbc v8.2.1135
patch 8.2.1135: Vim9: getting a dict member may not work
Commit: https://github.com/vim/vim/commit/50788ef34947aeb1729604cd3876845afbd15e3c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 5 16:51:26 2020 +0200
patch 8.2.1135: Vim9: getting a dict member may not work
Problem: Vim9: getting a dict member may not work.
Solution: Clear the dict only after copying the item.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 Jul 2020 17:00:03 +0200 |
parents | 61a9e8f67262 |
children | 93bfa89a916f |
files | src/testdir/test_vim9_expr.vim src/version.c src/vim9execute.c |
diffstat | 3 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1128,6 +1128,8 @@ def Test_expr7_dict_vim9script() CheckScriptFailure(lines, 'E1069:') enddef +let g:oneString = 'one' + def Test_expr_member() assert_equal(1, g:dict_one.one) let d: dict<number> = g:dict_one @@ -1135,6 +1137,7 @@ def Test_expr_member() # getting the one member should clear the dict after getting the item assert_equal('one', #{one: 'one'}.one) + assert_equal('one', #{one: 'one'}[g:oneString]) call CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:') call CheckDefExecFailure(["let d: dict<any>", "echo d['a']"], 'E716:')
--- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1135, +/**/ 1134, /**/ 1133,
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2166,6 +2166,7 @@ call_def_function( dict_T *dict; char_u *key; dictitem_T *di; + typval_T temp_tv; // dict member: dict is at stack-2, key at stack-1 tv = STACK_TV_BOT(-2); @@ -2181,10 +2182,14 @@ call_def_function( semsg(_(e_dictkey), key); goto failed; } + clear_tv(tv); --ectx.ec_stack.ga_len; - clear_tv(tv); - clear_tv(STACK_TV_BOT(-1)); - copy_tv(&di->di_tv, STACK_TV_BOT(-1)); + // Clear the dict after getting the item, to avoid that it + // make the item invalid. + tv = STACK_TV_BOT(-1); + temp_tv = *tv; + copy_tv(&di->di_tv, tv); + clear_tv(&temp_tv); } break;