Skip to content

Commit 6e48b84

Browse files
committed
patch 8.2.3326: Vim9: no error passing an empty list of the wrong type
Problem: Vim9: no error passing an empty list of the wrong type. Solution: Use ISN_SETTYPE also for "list<any>". (closes #8732)
1 parent 52eb372 commit 6e48b84

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/testdir/test_vim9_disassemble.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def Test_disassemble_list_assign()
435435
'\d STORE $1\_s*' ..
436436
'var l: list<any>\_s*' ..
437437
'\d NEWLIST size 0\_s*' ..
438+
'\d SETTYPE list<any>\_s*' ..
438439
'\d STORE $2\_s*' ..
439440
'\[x, y; l\] = g:stringlist\_s*' ..
440441
'\d LOADG g:stringlist\_s*' ..

src/testdir/test_vim9_func.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,27 @@ def Test_check_func_arg_types()
29302930
CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:')
29312931
enddef
29322932

2933+
def Test_list_any_type_checked()
2934+
var lines =<< trim END
2935+
vim9script
2936+
def Foo()
2937+
--decl--
2938+
Bar(l)
2939+
enddef
2940+
def Bar(ll: list<dict<any>>)
2941+
enddef
2942+
Foo()
2943+
END
2944+
lines[2] = 'var l: list<any>'
2945+
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<any>', 2)
2946+
2947+
lines[2] = 'var l: list<any> = []'
2948+
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<any>', 2)
2949+
2950+
lines[2] = 'var l: list<any> = [11]'
2951+
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<number>', 2)
2952+
enddef
2953+
29332954
def Test_compile_error()
29342955
var lines =<< trim END
29352956
def g:Broken()

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3326,
758760
/**/
759761
3325,
760762
/**/

src/vim9compile.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ generate_NEWLIST(cctx_T *cctx, int count)
15981598

15991599
// get the member type from all the items on the stack.
16001600
if (count == 0)
1601-
member = &t_void;
1601+
member = &t_unknown;
16021602
else
16031603
member = get_member_type_from_stack(
16041604
((type_T **)stack->ga_data) + stack->ga_len, count, 1,
@@ -7190,10 +7190,15 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
71907190
&& (lhs.lhs_type->tt_type == VAR_DICT
71917191
|| lhs.lhs_type->tt_type == VAR_LIST)
71927192
&& lhs.lhs_type->tt_member != NULL
7193-
&& lhs.lhs_type->tt_member != &t_any
7193+
&& !(lhs.lhs_type->tt_member == &t_any
7194+
&& oplen > 0
7195+
&& rhs_type != NULL
7196+
&& rhs_type->tt_type == lhs.lhs_type->tt_type
7197+
&& rhs_type->tt_member != &t_unknown)
71947198
&& lhs.lhs_type->tt_member != &t_unknown)
71957199
// Set the type in the list or dict, so that it can be checked,
7196-
// also in legacy script.
7200+
// also in legacy script. Not for "list<any> = val", then the
7201+
// type of "val" is used.
71977202
generate_SETTYPE(cctx, lhs.lhs_type);
71987203

71997204
if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL)

0 commit comments

Comments
 (0)