]> granicus.if.org Git - vim/commitdiff
patch 8.2.1134: Vim9: getting a list member may not work v8.2.1134
authorBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 14:42:13 +0000 (16:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 14:42:13 +0000 (16:42 +0200)
Problem:    Vim9: getting a list member may not work.
Solution:   Clear the list only after copying the item. (closes #6393)

src/testdir/test_vim9_expr.vim
src/version.c
src/vim9execute.c

index 3bf578059f1944c53047776f4fd1f1c6e3c03ce3..aef1815121a6e40ee11cbad9ae93a75656cb6468 100644 (file)
@@ -1141,6 +1141,11 @@ def Test_expr_member()
   call CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list')
 enddef
 
+def Test_expr_index()
+  # getting the one member should clear the list only after getting the item
+  assert_equal('bbb', ['aaa', 'bbb', 'ccc'][1])
+enddef
+
 def Test_expr_member_vim9script()
   let lines =<< trim END
       vim9script
index 6a2295191e36f0fb09c3869bfdccd0fa66e84c78..8774b2a8d91922485a1b1240accaebad19d9ea69 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1134,
 /**/
     1133,
 /**/
index bcacaabaa00a8d84094c9d63af281429b3c23144..47e072e5492e0728e71b2d0cc93e4777c989f326 100644 (file)
@@ -2085,6 +2085,7 @@ call_def_function(
                    list_T      *list;
                    varnumber_T n;
                    listitem_T  *li;
+                   typval_T    temp_tv;
 
                    // list index: list is at stack-2, index at stack-1
                    tv = STACK_TV_BOT(-2);
@@ -2109,8 +2110,12 @@ call_def_function(
                        goto failed;
                    }
                    --ectx.ec_stack.ga_len;
-                   clear_tv(STACK_TV_BOT(-1));
-                   copy_tv(&li->li_tv, STACK_TV_BOT(-1));
+                   // Clear the list after getting the item, to avoid that it
+                   // make the item invalid.
+                   tv = STACK_TV_BOT(-1);
+                   temp_tv = *tv;
+                   copy_tv(&li->li_tv, tv);
+                   clear_tv(&temp_tv);
                }
                break;