]> granicus.if.org Git - vim/commitdiff
patch 8.2.3127: Vim9: no error when adding number to list of string v8.2.3127
authorBram Moolenaar <Bram@vim.org>
Thu, 8 Jul 2021 18:53:40 +0000 (20:53 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 8 Jul 2021 18:53:40 +0000 (20:53 +0200)
Problem:    Vim9: no error when adding number to list of string.
Solution:   Check the value type. (closes #8529)

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

index 6041bd2c39a7fa75580e2fc4d94871bc6d6c46de..9aec823eef2d3617ff243061d8fca385b41eb582 100644 (file)
@@ -597,13 +597,16 @@ list_append(list_T *l, listitem_T *item)
 
 /*
  * Append typval_T "tv" to the end of list "l".  "tv" is copied.
- * Return FAIL when out of memory.
+ * Return FAIL when out of memory or the type is wrong.
  */
     int
 list_append_tv(list_T *l, typval_T *tv)
 {
     listitem_T *li = listitem_alloc();
 
+    if (l->lv_type != NULL && l->lv_type->tt_member != NULL
+               && check_typval_arg_type(l->lv_type->tt_member, tv, 0) == FAIL)
+       return FAIL;
     if (li == NULL)
        return FAIL;
     copy_tv(tv, &li->li_tv);
index f6b5a099b73d363e728b4c101ced167b69d1fc51..8a6af5734d2d8d4313b04ad68a8e99140930c1a1 100644 (file)
@@ -104,6 +104,13 @@ def Test_add_list()
       add(l, 123)
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      vim9script
+      var l: list<string> = ['a']
+      l->add(123)
+  END
+  CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
 enddef
 
 def Test_add_blob()
index ff1bb4349498a0a4754d9e3ac392dc239f1ce304..7bca3a002c366f3da9f56cd1e9fb2e8d701d87ed 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3127,
 /**/
     3126,
 /**/