Problem: Vim9: getting a dict member may not work.
Solution: Clear the dict only after copying the item. (closes #6390)
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')
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1127,
/**/
1126,
/**/
{
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)
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;