Skip to content

Commit a71e263

Browse files
committed
patch 8.2.1374: Vim9: error for assigning empty list to script variable
Problem: Vim9: error for assigning empty list to script variable. Solution: Use t_unknown for empty list member. (closes #6595)
1 parent f9b2b49 commit a71e263

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,20 @@ def Test_let_type_check()
27822782
let var: asdf
27832783
END
27842784
CheckScriptFailure(lines, 'E1010:')
2785+
2786+
lines =<< trim END
2787+
vim9script
2788+
let s:l: list<number>
2789+
s:l = []
2790+
END
2791+
CheckScriptSuccess(lines)
2792+
2793+
lines =<< trim END
2794+
vim9script
2795+
let s:d: dict<number>
2796+
s:d = {}
2797+
END
2798+
CheckScriptSuccess(lines)
27852799
enddef
27862800

27872801
def Test_forward_declaration()

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1374,
757759
/**/
758760
1373,
759761
/**/

src/vim9compile.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,22 +502,25 @@ typval2type(typval_T *tv, garray_T *type_gap)
502502
if (tv->v_type == VAR_STRING)
503503
return &t_string;
504504

505-
if (tv->v_type == VAR_LIST
506-
&& tv->vval.v_list != NULL
507-
&& tv->vval.v_list->lv_first != NULL)
505+
if (tv->v_type == VAR_LIST)
508506
{
507+
if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
508+
return &t_list_empty;
509+
509510
// Use the type of the first member, it is the most specific.
510511
member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap);
511512
return get_list_type(member_type, type_gap);
512513
}
513514

514-
if (tv->v_type == VAR_DICT
515-
&& tv->vval.v_dict != NULL
516-
&& tv->vval.v_dict->dv_hashtab.ht_used > 0)
515+
if (tv->v_type == VAR_DICT)
517516
{
518517
dict_iterator_T iter;
519518
typval_T *value;
520519

520+
if (tv->vval.v_dict == NULL
521+
|| tv->vval.v_dict->dv_hashtab.ht_used == 0)
522+
return &t_dict_empty;
523+
521524
// Use the type of the first value, it is the most specific.
522525
dict_iterate_start(tv, &iter);
523526
dict_iterate_next(&iter, &value);

0 commit comments

Comments
 (0)