diff src/list.c @ 25603:525ef4d1d412 v8.2.3338

patch 8.2.3338: Vim9: no type check when assigning a list range Commit: https://github.com/vim/vim/commit/89071cb6a116a74f78f77a1853e6fada44872a15 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 13 18:20:09 2021 +0200 patch 8.2.3338: Vim9: no type check when assigning a list range Problem: Vim9: no type check when assigning a list range. (Naohiro Ono) Solution: Check the member type. (closes https://github.com/vim/vim/issues/8750)
author Bram Moolenaar <Bram@vim.org>
date Fri, 13 Aug 2021 18:30:03 +0200
parents b85e44974a08
children 9edad9a8cca6
line wrap: on
line diff
--- a/src/list.c
+++ b/src/list.c
@@ -852,6 +852,7 @@ list_assign_range(
     long	idx1 = idx1_arg;
     listitem_T	*first_li = list_find_index(dest, &idx1);
     long	idx;
+    type_T	*member_type = NULL;
 
     /*
      * Check whether any of the list items is locked before making any changes.
@@ -869,6 +870,10 @@ list_assign_range(
 	++idx;
     }
 
+    if (in_vim9script() && dest->lv_type != NULL
+					   && dest->lv_type->tt_member != NULL)
+	member_type = dest->lv_type->tt_member;
+
     /*
      * Assign the List values to the list items.
      */
@@ -880,6 +885,10 @@ list_assign_range(
 	    tv_op(&dest_li->li_tv, &src_li->li_tv, op);
 	else
 	{
+	    if (member_type != NULL
+		    && check_typval_arg_type(member_type, &src_li->li_tv,
+							      NULL, 0) == FAIL)
+		return FAIL;
 	    clear_tv(&dest_li->li_tv);
 	    copy_tv(&src_li->li_tv, &dest_li->li_tv);
 	}