Skip to content

Commit f450804

Browse files
committed
patch 9.0.1202: crash when iterating over list of objects
Problem: Crash when iterating over list of objects. Solution: Do not make a copy of tt_member for object or class. (closes #11823)
1 parent 4cae845 commit f450804

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/testdir/test_vim9_class.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,27 @@ def Test_assignment_with_operator()
219219
v9.CheckScriptSuccess(lines)
220220
enddef
221221

222+
def Test_list_of_objects()
223+
var lines =<< trim END
224+
vim9script
225+
226+
class Foo
227+
def Add()
228+
enddef
229+
endclass
230+
231+
def ProcessList(fooList: list<Foo>)
232+
for foo in fooList
233+
foo.Add()
234+
endfor
235+
enddef
236+
237+
var l: list<Foo> = [Foo.new()]
238+
ProcessList(l)
239+
END
240+
v9.CheckScriptSuccess(lines)
241+
enddef
242+
222243
def Test_class_default_new()
223244
var lines =<< trim END
224245
vim9script

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1202,
698700
/**/
699701
1201,
700702
/**/

src/vim9type.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ copy_type_deep_rec(type_T *type, garray_T *type_gap, garray_T *seen_types)
8686
((type_T **)seen_types->ga_data)[seen_types->ga_len * 2 + 1] = copy;
8787
++seen_types->ga_len;
8888

89-
if (copy->tt_member != NULL)
89+
if (copy->tt_member != NULL
90+
&& copy->tt_type != VAR_OBJECT && copy->tt_type != VAR_CLASS)
9091
copy->tt_member = copy_type_deep_rec(copy->tt_member,
9192
type_gap, seen_types);
9293

0 commit comments

Comments
 (0)