]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4293: Vim9: when copying a list it gets type list<any> v8.2.4293
authorBram Moolenaar <Bram@vim.org>
Thu, 3 Feb 2022 21:47:34 +0000 (21:47 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 3 Feb 2022 21:47:34 +0000 (21:47 +0000)
Problem:    Vim9: when copying a list it gets type list<any> even when the
            original list did not have a type.
Solution:   Only set the type when the original list has a type. (closes #9692)

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

index 86c16793f9cb4bb13f1976a5d86908e7bb4e3ca0..3a6ea97668b36c9b53f1a5f3916ebdde042930ad 100644 (file)
@@ -1216,7 +1216,11 @@ list_copy(list_T *orig, int deep, int top, int copyID)
     copy = list_alloc();
     if (copy != NULL)
     {
-       copy->lv_type = alloc_type(top || deep ? &t_list_any: orig->lv_type);
+       if (orig->lv_type == NULL)
+           copy->lv_type = NULL;
+       else
+           copy->lv_type = alloc_type(top || deep
+                                                ? &t_list_any: orig->lv_type);
        if (copyID != 0)
        {
            // Do this before adding the items, because one of the items may
index c6466d39a00d0097f8fcd4af53cd6f12d2a77d73..a4e3e9e0f27a7f8df38310fc52b4a3484478495a 100644 (file)
@@ -1495,6 +1495,9 @@ def Test_expr5_list_add()
 
       # result of glob() is "any", runtime type check
       var sl: list<string> = glob('*.txt', false, true) + ['']
+
+      var lln: list<list<number>> = [[1] + [2]]
+      assert_equal([[1, 2]], lln)
   END
   v9.CheckDefAndScriptSuccess(lines)
 enddef
index 04199782e1cb232ae0ac273365d46a2109e9137e..5140eb95207d5f126a5b8f97a198102456b4a46d 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4293,
 /**/
     4292,
 /**/