summaryrefslogtreecommitdiff
path: root/src/vim9type.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-03 12:34:05 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-03 12:34:05 +0000
commit2d3ac2e03093c4b0ae5d18c5f2f51ae0c2a9ec72 (patch)
treed2b934718119e9e54d1bfeb02424b818e315385e /src/vim9type.c
parent381692b6f1c2ec9b73a139500286ddc9347a1c01 (diff)
downloadvim-git-8.2.4287.tar.gz
patch 8.2.4287: cannot assign empty list with type to variable with list typev8.2.4287
Problem: Cannot assign empty list with any list type to variable with specific list type. Solution: Use unknown list type for empty list if the specified type is any.
Diffstat (limited to 'src/vim9type.c')
-rw-r--r--src/vim9type.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/vim9type.c b/src/vim9type.c
index f184171c1..f72698cb9 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -344,7 +344,11 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int flags)
list_T *l = tv->vval.v_list;
listitem_T *li;
- if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL))
+ // An empty list has type list<unknown>, unless the type was specified
+ // and is not list<any>. This matters when assigning to a variable
+ // with a specific list type.
+ if (l == NULL || (l->lv_first == NULL
+ && (l->lv_type == NULL || l->lv_type->tt_member == &t_any)))
return &t_list_empty;
if ((flags & TVTT_DO_MEMBER) == 0)
return &t_list_any;