Mercurial > vim
comparison src/vim9type.c @ 27519:7898c7847293 v8.2.4287
patch 8.2.4287: cannot assign empty list with type to variable with list type
Commit: https://github.com/vim/vim/commit/2d3ac2e03093c4b0ae5d18c5f2f51ae0c2a9ec72
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 3 12:34:05 2022 +0000
patch 8.2.4287: cannot assign empty list with type to variable with list type
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 03 Feb 2022 13:45:03 +0100 |
parents | f00a7a2bee21 |
children | 5bf2fca4f967 |
comparison
equal
deleted
inserted
replaced
27518:67c5f3cebf28 | 27519:7898c7847293 |
---|---|
342 if (tv->v_type == VAR_LIST) | 342 if (tv->v_type == VAR_LIST) |
343 { | 343 { |
344 list_T *l = tv->vval.v_list; | 344 list_T *l = tv->vval.v_list; |
345 listitem_T *li; | 345 listitem_T *li; |
346 | 346 |
347 if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL)) | 347 // An empty list has type list<unknown>, unless the type was specified |
348 // and is not list<any>. This matters when assigning to a variable | |
349 // with a specific list type. | |
350 if (l == NULL || (l->lv_first == NULL | |
351 && (l->lv_type == NULL || l->lv_type->tt_member == &t_any))) | |
348 return &t_list_empty; | 352 return &t_list_empty; |
349 if ((flags & TVTT_DO_MEMBER) == 0) | 353 if ((flags & TVTT_DO_MEMBER) == 0) |
350 return &t_list_any; | 354 return &t_list_any; |
351 // If the type is list<any> go through the members, it may end up a | 355 // If the type is list<any> go through the members, it may end up a |
352 // more specific type. | 356 // more specific type. |