Patch 8.2.1291

4 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 25, 2020, 10:34:39 AM7/25/20
to vim...@googlegroups.com

Patch 8.2.1291
Problem: Vim9: type of varargs items is not checked.
Solution: Check the list item types. (closes #6523)
Files: src/vim9execute.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1290/src/vim9execute.c 2020-07-22 21:45:10.529629648 +0200
--- src/vim9execute.c 2020-07-25 16:23:09.755074478 +0200
***************
*** 755,763 ****
argc -= vararg_count;
if (exe_newlist(vararg_count, &ectx) == FAIL)
goto failed_early;
if (defcount > 0)
// Move varargs list to below missing default arguments.
! *STACK_TV_BOT(defcount- 1) = *STACK_TV_BOT(-1);
--ectx.ec_stack.ga_len;
}

--- 755,781 ----
argc -= vararg_count;
if (exe_newlist(vararg_count, &ectx) == FAIL)
goto failed_early;
+
+ // Check the type of the list items.
+ tv = STACK_TV_BOT(-1);
+ if (ufunc->uf_va_type != NULL
+ && ufunc->uf_va_type->tt_member != &t_any
+ && tv->vval.v_list != NULL)
+ {
+ type_T *expected = ufunc->uf_va_type->tt_member;
+ listitem_T *li = tv->vval.v_list->lv_first;
+
+ for (idx = 0; idx < vararg_count; ++idx)
+ {
+ if (check_typval_type(expected, &li->li_tv) == FAIL)
+ goto failed_early;
+ li = li->li_next;
+ }
+ }
+
if (defcount > 0)
// Move varargs list to below missing default arguments.
! *STACK_TV_BOT(defcount - 1) = *STACK_TV_BOT(-1);
--ectx.ec_stack.ga_len;
}

*** ../vim-8.2.1290/src/testdir/test_vim9_func.vim 2020-07-24 18:47:18.607480118 +0200
--- src/testdir/test_vim9_func.vim 2020-07-25 16:32:05.471964122 +0200
***************
*** 164,170 ****
assert_equal('one,foo', MyDefVarargs('one'))
assert_equal('one,two', MyDefVarargs('one', 'two'))
assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
! call CheckDefFailure(['MyDefVarargs("one", 22)'], 'E1013: argument 2: type mismatch, expected string but got number')
enddef

let s:value = ''
--- 164,218 ----
assert_equal('one,foo', MyDefVarargs('one'))
assert_equal('one,two', MyDefVarargs('one', 'two'))
assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three'))
! CheckDefFailure(['MyDefVarargs("one", 22)'],
! 'E1013: argument 2: type mismatch, expected string but got number')
! CheckDefFailure(['MyDefVarargs("one", "two", 123)'],
! 'E1013: argument 3: type mismatch, expected string but got number')
!
! let lines =<< trim END
! vim9script
! def Func(...l: list<string>)
! echo l
! enddef
! Func('a', 'b', 'c')
! END
! CheckScriptSuccess(lines)
!
! lines =<< trim END
! vim9script
! def Func(...l: list<string>)
! echo l
! enddef
! Func()
! END
! CheckScriptSuccess(lines)
!
! lines =<< trim END
! vim9script
! def Func(...l: list<string>)
! echo l
! enddef
! Func(1, 2, 3)
! END
! CheckScriptFailure(lines, 'E1013:')
!
! lines =<< trim END
! vim9script
! def Func(...l: list<string>)
! echo l
! enddef
! Func('a', 9)
! END
! CheckScriptFailure(lines, 'E1013:')
!
! lines =<< trim END
! vim9script
! def Func(...l: list<string>)
! echo l
! enddef
! Func(1, 'a')
! END
! CheckScriptFailure(lines, 'E1013:')
enddef

let s:value = ''
*** ../vim-8.2.1290/src/version.c 2020-07-25 15:41:04.412638651 +0200
--- src/version.c 2020-07-25 16:24:07.010681696 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1291,
/**/

--
hundred-and-one symptoms of being an internet addict:
84. Books in your bookcase bear the names Bongo, WinSock and Inside OLE

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages