Patch 8.2.1127
Problem:    Vim9: getting a dict member may not work.
Solution:   Clear the dict only after copying the item. (closes #6390)
Files:      src/vim9execute.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.1126/src/vim9execute.c   2020-07-01 18:29:23.685143414 +0200
--- src/vim9execute.c   2020-07-04 19:18:47.040316754 +0200
***************
*** 2188,2193 ****
--- 2188,2194 ----
                {
                    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,2210 ****
                        semsg(_(e_dictkey), iptr->isn_arg.string);
                        goto failed;
                    }
!                   clear_tv(tv);
                    copy_tv(&di->di_tv, tv);
                }
                break;
  
--- 2204,2214 ----
                        semsg(_(e_dictkey), iptr->isn_arg.string);
                        goto failed;
                    }
!                   // 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;
  
*** ../vim-8.2.1126/src/testdir/test_vim9_expr.vim      2020-07-03 
21:09:48.865268894 +0200
--- src/testdir/test_vim9_expr.vim      2020-07-04 19:18:30.620395724 +0200
***************
*** 1133,1138 ****
--- 1133,1141 ----
    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')
*** ../vim-8.2.1126/src/version.c       2020-07-04 17:39:07.510515698 +0200
--- src/version.c       2020-07-04 19:16:44.636905930 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1127,
  /**/

-- 
Hacker: Someone skilled in computer programming (good guy).
Cracker: A hacker that uses his skills to crack software (bad guy).

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202007041720.064HKBTQ368987%40masaka.moolenaar.net.

Raspunde prin e-mail lui