Skip to content

Commit 645a428

Browse files
h-eastchrisbra
authored andcommitted
patch 9.1.1087: Vim9: import with extends may crash
Problem: Vim9: import with extends may crash Solution: check otv for being NULL before trying to access it (Hirohito Higashi) closes: #16601 Signed-off-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 76bdb82 commit 645a428

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/testdir/test_vim9_import.vim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,4 +3420,42 @@ def Test_imported_class_as_def_func_rettype()
34203420
v9.CheckScriptSuccess(lines)
34213421
enddef
34223422

3423+
" Test for don't crash when using a combination of import and class extends
3424+
def Test_vim9_import_and_class_extends()
3425+
var lines =<< trim END
3426+
vim9script
3427+
import './cccc.vim'
3428+
export class Property extends cccc.Run
3429+
public var value: string
3430+
def new(this.value)
3431+
cccc.Run.value2 = this.value
3432+
enddef
3433+
endclass
3434+
END
3435+
writefile(lines, './aaaa.vim', 'D')
3436+
3437+
lines =<< trim END
3438+
vim9script
3439+
export class Run
3440+
public var value2: string
3441+
def new(this.value)
3442+
enddef
3443+
endclass
3444+
END
3445+
writefile(lines, './cccc.vim', 'D')
3446+
3447+
lines =<< trim END
3448+
vim9script
3449+
import './aaaa.vim'
3450+
class View
3451+
var content = aaaa.Property.new('')
3452+
endclass
3453+
3454+
var myView = View.new('This should be ok')
3455+
assert_equal('This should be ok', myView.content.value)
3456+
END
3457+
# TODO: The root cause will be identified later.
3458+
v9.CheckScriptFailure(lines, 'E1099: Unknown error while executing new', 7)
3459+
enddef
3460+
34233461
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1087,
707709
/**/
708710
1086,
709711
/**/

src/vim9execute.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,8 +2461,14 @@ execute_storeindex(isn_T *iptr, ectx_T *ectx)
24612461
otv = class->class_members_tv;
24622462
}
24632463

2464-
clear_tv(&otv[lidx]);
2465-
otv[lidx] = *tv;
2464+
if (otv != NULL)
2465+
{
2466+
clear_tv(&otv[lidx]);
2467+
otv[lidx] = *tv;
2468+
}
2469+
else
2470+
status = FAIL;
2471+
24662472
}
24672473
else
24682474
{

0 commit comments

Comments
 (0)