Patch 8.2.3326
Problem: Vim9: no error passing an empty list of the wrong type.
Solution: Use ISN_SETTYPE also for "list<any>". (closes #8732)
Files: src/vim9compile.c, src/testdir/test_vim9_func.vim,
src/testdir/test_vim9_disassemble.vim
*** ../vim-8.2.3325/src/vim9compile.c 2021-08-10 19:52:57.474235537 +0200
--- src/vim9compile.c 2021-08-10 22:39:26.703543703 +0200
***************
*** 1598,1604 ****
// get the member type from all the items on the stack.
if (count == 0)
! member = &t_void;
else
member = get_member_type_from_stack(
((type_T **)stack->ga_data) + stack->ga_len, count, 1,
--- 1598,1604 ----
// get the member type from all the items on the stack.
if (count == 0)
! member = &t_unknown;
else
member = get_member_type_from_stack(
((type_T **)stack->ga_data) + stack->ga_len, count, 1,
***************
*** 7190,7199 ****
&& (lhs.lhs_type->tt_type == VAR_DICT
|| lhs.lhs_type->tt_type == VAR_LIST)
&& lhs.lhs_type->tt_member != NULL
! && lhs.lhs_type->tt_member != &t_any
&& lhs.lhs_type->tt_member != &t_unknown)
// Set the type in the list or dict, so that it can be checked,
! // also in legacy script.
generate_SETTYPE(cctx, lhs.lhs_type);
if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL)
--- 7190,7204 ----
&& (lhs.lhs_type->tt_type == VAR_DICT
|| lhs.lhs_type->tt_type == VAR_LIST)
&& lhs.lhs_type->tt_member != NULL
! && !(lhs.lhs_type->tt_member == &t_any
! && oplen > 0
! && rhs_type != NULL
! && rhs_type->tt_type == lhs.lhs_type->tt_type
! && rhs_type->tt_member != &t_unknown)
&& lhs.lhs_type->tt_member != &t_unknown)
// Set the type in the list or dict, so that it can be checked,
! // also in legacy script. Not for "list<any> = val", then the
! // type of "val" is used.
generate_SETTYPE(cctx, lhs.lhs_type);
if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL)
*** ../vim-8.2.3325/src/testdir/test_vim9_func.vim 2021-08-08
19:07:32.924667679 +0200
--- src/testdir/test_vim9_func.vim 2021-08-10 22:46:52.306299337 +0200
***************
*** 2930,2935 ****
--- 2930,2956 ----
CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:')
enddef
+ def Test_list_any_type_checked()
+ var lines =<< trim END
+ vim9script
+ def Foo()
+ --decl--
+ Bar(l)
+ enddef
+ def Bar(ll: list<dict<any>>)
+ enddef
+ Foo()
+ END
+ lines[2] = 'var l: list<any>'
+ CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected
list<dict<any>> but got list<any>', 2)
+
+ lines[2] = 'var l: list<any> = []'
+ CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected
list<dict<any>> but got list<any>', 2)
+
+ lines[2] = 'var l: list<any> = [11]'
+ CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected
list<dict<any>> but got list<number>', 2)
+ enddef
+
def Test_compile_error()
var lines =<< trim END
def g:Broken()
*** ../vim-8.2.3325/src/testdir/test_vim9_disassemble.vim 2021-08-07
16:30:35.109065179 +0200
--- src/testdir/test_vim9_disassemble.vim 2021-08-10 22:21:27.558644938
+0200
***************
*** 435,440 ****
--- 435,441 ----
'\d STORE $1\_s*' ..
'var l: list<any>\_s*' ..
'\d NEWLIST size 0\_s*' ..
+ '\d SETTYPE list<any>\_s*' ..
'\d STORE $2\_s*' ..
'\[x, y; l\] = g:stringlist\_s*' ..
'\d LOADG g:stringlist\_s*' ..
*** ../vim-8.2.3325/src/version.c 2021-08-10 21:39:17.041820459 +0200
--- src/version.c 2021-08-10 22:23:37.650290609 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3326,
/**/
--
GUEST: He's killed the best man!
SECOND GUEST: (holding a limp WOMAN) He's killed my auntie.
FATHER: No, please! This is supposed to be a happy occasion! Let's
not bicker and argue about who killed who ...
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// 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/202108102052.17AKqaCK2750638%40masaka.moolenaar.net.