diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-01-15 16:54:57 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-01-15 16:54:57 +0000 |
commit | f450804e1438307c79a62053f8c32eef1508383a (patch) | |
tree | 2590180e091fac04509491286afdfb81e47c44f2 | |
parent | 4cae845ce32797bcae845aacf740ed865b479f34 (diff) |
patch 9.0.1202: crash when iterating over list of objectsv9.0.1202
Problem: Crash when iterating over list of objects.
Solution: Do not make a copy of tt_member for object or class.
(closes #11823)
-rw-r--r-- | src/testdir/test_vim9_class.vim | 21 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9type.c | 3 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 56b2dad7e0..28af68b386 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -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 diff --git a/src/version.c b/src/version.c index e4674e410a..4c9e486f28 100644 --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1202, +/**/ 1201, /**/ 1200, diff --git a/src/vim9type.c b/src/vim9type.c index 6fb6b2b257..9bb53e2fa2 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -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); |