Skip to content

Commit

Permalink
patch 8.2.1135: Vim9: getting a dict member may not work
Browse files Browse the repository at this point in the history
Problem:    Vim9: getting a dict member may not work.
Solution:   Clear the dict only after copying the item.
  • Loading branch information
brammool committed Jul 5, 2020
1 parent 435d897 commit 50788ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/testdir/test_vim9_expr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1128,13 +1128,16 @@ 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
assert_equal(1, d['one'])

# 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:')
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1135,
/**/
1134,
/**/
Expand Down
11 changes: 8 additions & 3 deletions src/vim9execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -2181,10 +2182,14 @@ call_def_function(
semsg(_(e_dictkey), key);
goto failed;
}
--ectx.ec_stack.ga_len;
clear_tv(tv);
clear_tv(STACK_TV_BOT(-1));
copy_tv(&di->di_tv, STACK_TV_BOT(-1));
--ectx.ec_stack.ga_len;
// 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;

Expand Down

0 comments on commit 50788ef

Please sign in to comment.