summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-04 19:19:43 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-04 19:19:43 +0200
commitfb9d5c51c8b5b44863f974e1adbee9ae330e75ff (patch)
treef5b493a521ea2509acdc5aeba61c5ddf4ef64731
parenteeb27bfe28ad6f889c52628268acbe30a7584e30 (diff)
downloadvim-git-fb9d5c51c8b5b44863f974e1adbee9ae330e75ff.tar.gz
patch 8.2.1127: Vim9: getting a dict member may not workv8.2.1127
Problem: Vim9: getting a dict member may not work. Solution: Clear the dict only after copying the item. (closes #6390)
-rw-r--r--src/testdir/test_vim9_expr.vim3
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c6
3 files changed, 10 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index a604de2b0..3bf578059 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1133,6 +1133,9 @@ def Test_expr_member()
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)
+
call CheckDefFailure(["let x = g:dict_one.#$!"], 'E1002:')
call CheckDefExecFailure(["let d: dict<any>", "echo d['a']"], 'E716:')
call CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list')
diff --git a/src/version.c b/src/version.c
index d1607ae15..b406a6957 100644
--- 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 */
/**/
+ 1127,
+/**/
1126,
/**/
1125,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index b4acb35c1..bcacaabaa 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2188,6 +2188,7 @@ call_def_function(
{
dict_T *dict;
dictitem_T *di;
+ typval_T temp_tv;
tv = STACK_TV_BOT(-1);
if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
@@ -2203,8 +2204,11 @@ call_def_function(
semsg(_(e_dictkey), iptr->isn_arg.string);
goto failed;
}
- clear_tv(tv);
+ // Clear the dict after getting the item, to avoid that it
+ // make the item invalid.
+ temp_tv = *tv;
copy_tv(&di->di_tv, tv);
+ clear_tv(&temp_tv);
}
break;