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


*** ../vim-8.2.1134/src/vim9execute.c   2020-07-05 16:42:07.520252970 +0200
--- src/vim9execute.c   2020-07-05 16:50:32.198412619 +0200
***************
*** 2166,2171 ****
--- 2166,2172 ----
                    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);
***************
*** 2181,2190 ****
                        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));
                }
                break;
  
--- 2182,2195 ----
                        semsg(_(e_dictkey), key);
                        goto failed;
                    }
                    clear_tv(tv);
!                   --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;
  
*** ../vim-8.2.1134/src/testdir/test_vim9_expr.vim      2020-07-05 
16:42:07.520252970 +0200
--- src/testdir/test_vim9_expr.vim      2020-07-05 16:47:28.531050538 +0200
***************
*** 1128,1133 ****
--- 1128,1135 ----
    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
***************
*** 1135,1140 ****
--- 1137,1143 ----
  
    # 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:')
*** ../vim-8.2.1134/src/version.c       2020-07-05 16:42:07.520252970 +0200
--- src/version.c       2020-07-05 16:51:07.374293346 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1135,
  /**/

-- 
If you had to identify, in one word, the reason why the
human race has not achieved, and never will achieve, its
full potential, that word would be "meetings."

 /// 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/202007051451.065EpoPV589920%40masaka.moolenaar.net.

Raspunde prin e-mail lui