diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-07-08 20:53:40 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-08 20:53:40 +0200 |
commit | f32f099761e5ae0603149b305a0086e4f4627d81 (patch) | |
tree | cd44497f85e3acf1082fb5bbcb0c83a8d3ce3580 | |
parent | d4ab807d62c1a8262e78deb674c6750183bc030a (diff) |
patch 8.2.3127: Vim9: no error when adding number to list of stringv8.2.3127
Problem: Vim9: no error when adding number to list of string.
Solution: Check the value type. (closes #8529)
-rw-r--r-- | src/list.c | 5 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 7 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 13 insertions, 1 deletions
diff --git a/src/list.c b/src/list.c index 6041bd2c39..9aec823eef 100644 --- a/src/list.c +++ b/src/list.c @@ -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); diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index f6b5a099b7..8a6af5734d 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -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() diff --git a/src/version.c b/src/version.c index ff1bb43494..7bca3a002c 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3127, +/**/ 3126, /**/ 3125, |