summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-05 15:11:03 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-05 15:11:03 +0200
commita71e2633207557c31432c954194078cb6062d04f (patch)
treee5d021e419b5cffcd6895216307236402fd53d9e
parentf9b2b49663226235f94f08230fe9023caf80a6e9 (diff)
patch 8.2.1374: Vim9: error for assigning empty list to script variablev8.2.1374
Problem: Vim9: error for assigning empty list to script variable. Solution: Use t_unknown for empty list member. (closes #6595)
-rw-r--r--src/testdir/test_vim9_script.vim14
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c15
3 files changed, 25 insertions, 6 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index f99333c0cb..c50a0d337a 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2782,6 +2782,20 @@ def Test_let_type_check()
let var: asdf
END
CheckScriptFailure(lines, 'E1010:')
+
+ lines =<< trim END
+ vim9script
+ let s:l: list<number>
+ s:l = []
+ END
+ CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ let s:d: dict<number>
+ s:d = {}
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_forward_declaration()
diff --git a/src/version.c b/src/version.c
index 7b1b8d8c21..abf2af0c72 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1374,
+/**/
1373,
/**/
1372,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index dc10b4851b..e87634b31b 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -502,22 +502,25 @@ typval2type(typval_T *tv, garray_T *type_gap)
if (tv->v_type == VAR_STRING)
return &t_string;
- if (tv->v_type == VAR_LIST
- && tv->vval.v_list != NULL
- && tv->vval.v_list->lv_first != NULL)
+ if (tv->v_type == VAR_LIST)
{
+ if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
+ return &t_list_empty;
+
// Use the type of the first member, it is the most specific.
member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap);
return get_list_type(member_type, type_gap);
}
- if (tv->v_type == VAR_DICT
- && tv->vval.v_dict != NULL
- && tv->vval.v_dict->dv_hashtab.ht_used > 0)
+ if (tv->v_type == VAR_DICT)
{
dict_iterator_T iter;
typval_T *value;
+ if (tv->vval.v_dict == NULL
+ || tv->vval.v_dict->dv_hashtab.ht_used == 0)
+ return &t_dict_empty;
+
// Use the type of the first value, it is the most specific.
dict_iterate_start(tv, &iter);
dict_iterate_next(&iter, &value);