Patch 8.2.3127
Problem: Vim9: no error when adding number to list of string.
Solution: Check the value type. (closes #8529)
Files: src/list.c, src/testdir/test_vim9_builtin.vim
*** ../vim-8.2.3126/src/list.c 2021-06-27 22:03:28.645707721 +0200
--- src/list.c 2021-07-08 20:08:17.106445278 +0200
***************
*** 597,609 ****
/*
* Append typval_T "tv" to the end of list "l". "tv" is copied.
! * Return FAIL when out of memory.
*/
int
list_append_tv(list_T *l, typval_T *tv)
{
listitem_T *li = listitem_alloc();
if (li == NULL)
return FAIL;
copy_tv(tv, &li->li_tv);
--- 597,612 ----
/*
* Append typval_T "tv" to the end of list "l". "tv" is copied.
! * 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);
*** ../vim-8.2.3126/src/testdir/test_vim9_builtin.vim 2021-07-05
14:10:00.431729296 +0200
--- src/testdir/test_vim9_builtin.vim 2021-07-08 20:50:16.982922857 +0200
***************
*** 104,109 ****
--- 104,116 ----
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()
*** ../vim-8.2.3126/src/version.c 2021-07-08 19:22:09.238611461 +0200
--- src/version.c 2021-07-08 20:09:28.110323834 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3127,
/**/
--
hundred-and-one symptoms of being an internet addict:
95. Only communication in your household is through email.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202107081854.168IsI0l088089%40masaka.moolenaar.net.