Skip to content

Commit 114ec81

Browse files
erraelbrammool
authored andcommitted
patch 9.0.1605: crash when calling method on super in child constructor
Problem: Crash when calling method on super in child constructor. (Israel Chauca Fuentes) Solution: Clear the type list. (Ernie Rael, closes #12489, closes #12471)
1 parent abc8130 commit 114ec81

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,28 @@ def Test_using_base_class()
16361636
END
16371637
v9.CheckScriptSuccess(lines)
16381638
unlet g:result
1639+
1640+
# Using super, Child invokes Base method which has optional arg. #12471
1641+
lines =<< trim END
1642+
vim9script
1643+
1644+
class Base
1645+
this.success: bool = false
1646+
def Method(arg = 0)
1647+
this.success = true
1648+
enddef
1649+
endclass
1650+
1651+
class Child extends Base
1652+
def new()
1653+
super.Method()
1654+
enddef
1655+
endclass
1656+
1657+
var obj = Child.new()
1658+
assert_equal(true, obj.success)
1659+
END
1660+
v9.CheckScriptSuccess(lines)
16391661
enddef
16401662

16411663

src/userfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5651,8 +5651,8 @@ copy_function(ufunc_T *fp)
56515651
// type_T **uf_arg_types;
56525652
// type_T *uf_ret_type;
56535653

5654-
ufunc->uf_type_list.ga_len = 0;
5655-
ufunc->uf_type_list.ga_data = NULL;
5654+
// make uf_type_list empty
5655+
ga_init(&ufunc->uf_type_list);
56565656

56575657
// TODO: partial_T *uf_partial;
56585658

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+
1605,
698700
/**/
699701
1604,
700702
/**/

src/vim9class.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,9 @@ ex_class(exarg_T *eap)
10251025
if (*fup == NULL)
10261026
goto cleanup;
10271027

1028-
mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len);
1028+
if (gap->ga_len != 0)
1029+
mch_memmove(*fup, gap->ga_data,
1030+
sizeof(ufunc_T *) * gap->ga_len);
10291031
vim_free(gap->ga_data);
10301032
if (loop == 1)
10311033
cl->class_class_function_count_child = gap->ga_len;

0 commit comments

Comments
 (0)