diff options
| author | Bram Moolenaar <Bram@vim.org> | 2022-02-03 12:34:05 +0000 |
|---|---|---|
| committer | Bram Moolenaar <Bram@vim.org> | 2022-02-03 12:34:05 +0000 |
| commit | 2d3ac2e03093c4b0ae5d18c5f2f51ae0c2a9ec72 (patch) | |
| tree | d2b934718119e9e54d1bfeb02424b818e315385e /src/vim9type.c | |
| parent | 381692b6f1c2ec9b73a139500286ddc9347a1c01 (diff) | |
| download | vim-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.c | 6 |
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; |
