]> granicus.if.org Git - vim/commitdiff
patch 9.0.1202: crash when iterating over list of objects v9.0.1202
authorBram Moolenaar <Bram@vim.org>
Sun, 15 Jan 2023 16:54:57 +0000 (16:54 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 15 Jan 2023 16:54:57 +0000 (16:54 +0000)
Problem:    Crash when iterating over list of objects.
Solution:   Do not make a copy of tt_member for object or class.
            (closes #11823)

src/testdir/test_vim9_class.vim
src/version.c
src/vim9type.c

index 56b2dad7e07bffb54e1eb0f300b87fda6230f7a3..28af68b386ee02d481756cb6a2376d161df5b44a 100644 (file)
@@ -219,6 +219,27 @@ def Test_assignment_with_operator()
   v9.CheckScriptSuccess(lines)
 enddef
 
+def Test_list_of_objects()
+  var lines =<< trim END
+      vim9script
+
+      class Foo
+        def Add()
+        enddef
+      endclass
+
+      def ProcessList(fooList: list<Foo>)
+        for foo in fooList
+          foo.Add()
+        endfor
+      enddef
+
+      var l: list<Foo> = [Foo.new()]
+      ProcessList(l)
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 def Test_class_default_new()
   var lines =<< trim END
       vim9script
index e4674e410abcd56ab813ab57584492d38f16eae0..4c9e486f28717a73726cd152490c22e600a279b4 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1202,
 /**/
     1201,
 /**/
index 6fb6b2b257e0f58782a7f0e49c0eb4b4d1b06c00..9bb53e2fa2dc3dc0a990eb52adbfaf3cc7c19bc5 100644 (file)
@@ -86,7 +86,8 @@ copy_type_deep_rec(type_T *type, garray_T *type_gap, garray_T *seen_types)
     ((type_T **)seen_types->ga_data)[seen_types->ga_len * 2 + 1] = copy;
     ++seen_types->ga_len;
 
-    if (copy->tt_member != NULL)
+    if (copy->tt_member != NULL
+           && copy->tt_type != VAR_OBJECT && copy->tt_type != VAR_CLASS)
        copy->tt_member = copy_type_deep_rec(copy->tt_member,
                                                         type_gap, seen_types);