diff src/list.c @ 23458:d2b1269c2c68 v8.2.2272

patch 8.2.2272: Vim9: extend() can violate the type of a variable Commit: https://github.com/vim/vim/commit/aa210a3aeccc33c6051978017959126b037f94af Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 2 15:41:03 2021 +0100 patch 8.2.2272: Vim9: extend() can violate the type of a variable Problem: Vim9: extend() can violate the type of a variable. Solution: Add the type to the dictionary or list and check items against it. (closes #7593)
author Bram Moolenaar <Bram@vim.org>
date Sat, 02 Jan 2021 15:45:04 +0100
parents b545334ae654
children 1bb7fa4f9b35
line wrap: on
line diff
--- a/src/list.c
+++ b/src/list.c
@@ -270,6 +270,7 @@ list_free_list(list_T  *l)
     if (l->lv_used_next != NULL)
 	l->lv_used_next->lv_used_prev = l->lv_used_prev;
 
+    free_type(l->lv_type);
     vim_free(l);
 }
 
@@ -689,13 +690,17 @@ list_append_number(list_T *l, varnumber_
 /*
  * Insert typval_T "tv" in list "l" before "item".
  * If "item" is NULL append at the end.
- * Return FAIL when out of memory.
+ * Return FAIL when out of memory or the type is wrong.
  */
     int
 list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
 {
-    listitem_T	*ni = listitem_alloc();
+    listitem_T	*ni;
 
+    if (l->lv_type != NULL && l->lv_type->tt_member != NULL
+		    && check_typval_type(l->lv_type->tt_member, tv, 0) == FAIL)
+	return FAIL;
+    ni = listitem_alloc();
     if (ni == NULL)
 	return FAIL;
     copy_tv(tv, &ni->li_tv);