Skip to content

Commit

Permalink
patch 9.0.1202: crash when iterating over list of objects
Browse files Browse the repository at this point in the history
Problem:    Crash when iterating over list of objects.
Solution:   Do not make a copy of tt_member for object or class.
            (closes #11823)
  • Loading branch information
brammool committed Jan 15, 2023
1 parent 4cae845 commit f450804
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/testdir/test_vim9_class.vim
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1202,
/**/
1201,
/**/
Expand Down
3 changes: 2 additions & 1 deletion src/vim9type.c
Expand Up @@ -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);

Expand Down

0 comments on commit f450804

Please sign in to comment.