changeset 27549:2397b18d6f94 v8.2.4301

patch 8.2.4301: Vim9: type error for copy of dict Commit: https://github.com/vim/vim/commit/e0c2b2ceaa8ca2d0f412f17f4cf14fb4f7a3296f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 5 14:05:51 2022 +0000 patch 8.2.4301: Vim9: type error for copy of dict Problem: Vim9: type error for copy of dict. Solution: Do not use dict<any> but no type. (closes https://github.com/vim/vim/issues/9696)
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Feb 2022 15:15:02 +0100
parents 5bf66bc1e368
children eabeeeee4902
files src/dict.c src/testdir/test_vim9_builtin.vim src/version.c
diffstat 3 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/dict.c
+++ b/src/dict.c
@@ -306,7 +306,10 @@ dict_copy(dict_T *orig, int deep, int to
 	    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)
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -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()
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4301,
+/**/
     4300,
 /**/
     4299,