]> granicus.if.org Git - vim/commitdiff
patch 8.2.3338: Vim9: no type check when assigning a list range v8.2.3338
authorBram Moolenaar <Bram@vim.org>
Fri, 13 Aug 2021 16:20:09 +0000 (18:20 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 13 Aug 2021 16:20:09 +0000 (18:20 +0200)
Problem:    Vim9: no type check when assigning a list range. (Naohiro Ono)
Solution:   Check the member type. (closes #8750)

src/list.c
src/testdir/test_listdict.vim
src/version.c

index 04ddbfca15961e702d0968bc62e498cafa97312c..76101bac5e503c80e23ca927b3778c67e68fefb0 100644 (file)
@@ -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);
        }
index 8f8e34ceedae322f35db09b9f7c7d5552d2bce11..2eda9a8801e4c23cee58f7a64b92cda9b4efe4f9 100644 (file)
@@ -189,6 +189,12 @@ func Test_list_range_assign()
       call assert_equal([5, 6], l)
   END
   call CheckLegacyAndVim9Success(lines)
+
+  let lines =<< trim END
+    var l = [7]
+    l[:] = ['text']
+  END
+  call CheckDefAndScriptFailure(lines, 'E1012:', 2)
 endfunc
 
 " Test removing items in list
index 64137dbd0014d955d179b55d52eb153514cbd0f4..1acc17adf4dbd5e95e8bd1bb724b58df92b1dbc8 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3338,
 /**/
     3337,
 /**/