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 -- [email protected] -- 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    ///

-- 
-- 
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/202007251434.06PEYVhL329875%40masaka.moolenaar.net.

Raspunde prin e-mail lui