Patch 8.2.0207
Problem:    Crash when missing member type on list argument.
Solution:   Check for invalid type. (closes #5572)
Files:      src/userfunc.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.0206/src/userfunc.c      2020-02-03 20:50:55.672929674 +0100
--- src/userfunc.c      2020-02-04 21:49:52.620934309 +0100
***************
*** 2968,2973 ****
--- 2968,2978 ----
  
      if (eap->cmdidx == CMD_def)
      {
+       int lnum_save = SOURCING_LNUM;
+ 
+       // error messages are for the first function line
+       SOURCING_LNUM = sourcing_lnum_top;
+ 
        // parse the argument types
        ga_init2(&fp->uf_type_list, sizeof(type_T), 5);
  
***************
*** 2980,2995 ****
            fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len);
            if (fp->uf_arg_types != NULL)
            {
!               int i;
  
                for (i = 0; i < len; ++ i)
                {
                    p = ((char_u **)argtypes.ga_data)[i];
                    if (p == NULL)
                        // todo: get type from default value
!                       fp->uf_arg_types[i] = &t_any;
                    else
!                       fp->uf_arg_types[i] = parse_type(&p, &fp->uf_type_list);
                }
            }
            if (varargs)
--- 2985,3007 ----
            fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len);
            if (fp->uf_arg_types != NULL)
            {
!               int     i;
!               type_T  *type;
  
                for (i = 0; i < len; ++ i)
                {
                    p = ((char_u **)argtypes.ga_data)[i];
                    if (p == NULL)
                        // todo: get type from default value
!                       type = &t_any;
                    else
!                       type = parse_type(&p, &fp->uf_type_list);
!                   if (type == NULL)
!                   {
!                       SOURCING_LNUM = lnum_save;
!                       goto errret_2;
!                   }
!                   fp->uf_arg_types[i] = type;
                }
            }
            if (varargs)
***************
*** 3005,3010 ****
--- 3017,3027 ----
                    fp->uf_va_type = &t_any;
                else
                    fp->uf_va_type = parse_type(&p, &fp->uf_type_list);
+               if (fp->uf_va_type == NULL)
+               {
+                   SOURCING_LNUM = lnum_save;
+                   goto errret_2;
+               }
            }
            varargs = FALSE;
        }
*** ../vim-8.2.0206/src/testdir/test_vim9_script.vim    2020-02-04 
21:24:11.702500431 +0100
--- src/testdir/test_vim9_script.vim    2020-02-04 21:52:56.713125366 +0100
***************
*** 160,172 ****
  enddef
  
  def Test_return_type_wrong()
-   " TODO: why is ! needed for Mac and FreeBSD?
    CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 
'expected number but got string')
    CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected 
string but got number')
    CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected 
void but got string')
    CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void 
but got string')
  enddef
  
  def Test_try_catch()
    let l = []
    try
--- 160,175 ----
  enddef
  
  def Test_return_type_wrong()
    CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 
'expected number but got string')
    CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected 
string but got number')
    CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected 
void but got string')
    CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void 
but got string')
  enddef
  
+ def Test_arg_type_wrong()
+   CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 
'E1008: Missing <type>')
+ enddef
+ 
  def Test_try_catch()
    let l = []
    try
*** ../vim-8.2.0206/src/version.c       2020-02-04 21:24:11.702500431 +0100
--- src/version.c       2020-02-04 21:53:24.369141259 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     207,
  /**/

-- 
The startling truth finally became apparent, and it was this: Numbers
written on restaurant checks within the confines of restaurants do not follow
the same mathematical laws as numbers written on any other pieces of paper in
any other parts of the Universe.  This single statement took the scientific
world by storm.  So many mathematical conferences got held in such good
restaurants that many of the finest minds of a generation died of obesity and
heart failure, and the science of mathematics was put back by years.
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// 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/202002042054.014Ksldl001121%40masaka.moolenaar.net.

Raspunde prin e-mail lui