]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4301: Vim9: type error for copy of dict v8.2.4301
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Feb 2022 14:05:51 +0000 (14:05 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Feb 2022 14:05:51 +0000 (14:05 +0000)
Problem:    Vim9: type error for copy of dict.
Solution:   Do not use dict<any> but no type. (closes #9696)

src/dict.c
src/testdir/test_vim9_builtin.vim
src/version.c

index 06f38716b57ac22dea484fbb49fe5a8304d65734..c2dc6a7c23b3048d6e45f4ee566a301488623fe7 100644 (file)
@@ -306,7 +306,10 @@ dict_copy(dict_T *orig, int deep, int top, int copyID)
            orig->dv_copyID = copyID;
            orig->dv_copydict = copy;
        }
-       copy->dv_type = alloc_type(top || deep ? &t_dict_any : orig->dv_type);
+       if (orig->dv_type == NULL || top || deep)
+           copy->dv_type = NULL;
+       else
+           copy->dv_type = alloc_type(orig->dv_type);
 
        todo = (int)orig->dv_hashtab.ht_used;
        for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi)
index f7a5006b4556496130ba67d322b357d19405c619..6e53d270f1ec0f4977a49c8c4a8472a7bf9f85e3 100644 (file)
@@ -745,6 +745,9 @@ def Test_copy_return_type()
 
   var ndd: dict<dict<number>> = {a: {x: 1, y: 2}}
   assert_equal({x: 1, y: 2, z: 'x'}, ndd->deepcopy()['a']->extend({z: 'x'}))
+
+  var ldn: list<dict<number>> = [{a: 0}]->deepcopy()
+  assert_equal([{a: 0}], ldn)
 enddef
 
 def Test_count()
index b9945845d500bba73145dd6738f2b566189364d6..84ab4092ec46640af90ed2d9b94dc6c25f088af6 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4301,
 /**/
     4300,
 /**/