comparison src/vim9execute.c @ 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 64f664f9b23a
children caab594592cc
comparison
equal deleted inserted replaced
21167:61a9e8f67262 21168:f26a606e6dbc
2164 case ISN_MEMBER: 2164 case ISN_MEMBER:
2165 { 2165 {
2166 dict_T *dict; 2166 dict_T *dict;
2167 char_u *key; 2167 char_u *key;
2168 dictitem_T *di; 2168 dictitem_T *di;
2169 typval_T temp_tv;
2169 2170
2170 // dict member: dict is at stack-2, key at stack-1 2171 // dict member: dict is at stack-2, key at stack-1
2171 tv = STACK_TV_BOT(-2); 2172 tv = STACK_TV_BOT(-2);
2172 // no need to check for VAR_DICT, CHECKTYPE will check. 2173 // no need to check for VAR_DICT, CHECKTYPE will check.
2173 dict = tv->vval.v_dict; 2174 dict = tv->vval.v_dict;
2179 if ((di = dict_find(dict, key, -1)) == NULL) 2180 if ((di = dict_find(dict, key, -1)) == NULL)
2180 { 2181 {
2181 semsg(_(e_dictkey), key); 2182 semsg(_(e_dictkey), key);
2182 goto failed; 2183 goto failed;
2183 } 2184 }
2185 clear_tv(tv);
2184 --ectx.ec_stack.ga_len; 2186 --ectx.ec_stack.ga_len;
2185 clear_tv(tv); 2187 // Clear the dict after getting the item, to avoid that it
2186 clear_tv(STACK_TV_BOT(-1)); 2188 // make the item invalid.
2187 copy_tv(&di->di_tv, STACK_TV_BOT(-1)); 2189 tv = STACK_TV_BOT(-1);
2190 temp_tv = *tv;
2191 copy_tv(&di->di_tv, tv);
2192 clear_tv(&temp_tv);
2188 } 2193 }
2189 break; 2194 break;
2190 2195
2191 // dict member with string key 2196 // dict member with string key
2192 case ISN_STRINGMEMBER: 2197 case ISN_STRINGMEMBER: