Patch 8.2.4998
Problem:    Vim9: crash when using multiple funcref().
Solution:   Check if varargs type is NULL. (closes #10467)
Files:      src/vim9type.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.4997/src/vim9type.c      2022-03-31 20:02:52.422045605 +0100
--- src/vim9type.c      2022-05-22 13:32:56.083620515 +0100
***************
*** 807,813 ****
        else
            tv = &argvars[i];
        if (varargs && i >= type->tt_argcount - 1)
!           expected = type->tt_args[type->tt_argcount - 1]->tt_member;
        else
            expected = type->tt_args[i];
        if (check_typval_arg_type(expected, tv, NULL, i + 1) == FAIL)
--- 807,817 ----
        else
            tv = &argvars[i];
        if (varargs && i >= type->tt_argcount - 1)
!       {
!           expected = type->tt_args[type->tt_argcount - 1];
!           if (expected != NULL)
!               expected = expected->tt_member;
!       }
        else
            expected = type->tt_args[i];
        if (check_typval_arg_type(expected, tv, NULL, i + 1) == FAIL)
*** ../vim-8.2.4997/src/testdir/test_vim9_func.vim      2022-05-13 
13:50:32.815012765 +0100
--- src/testdir/test_vim9_func.vim      2022-05-22 13:32:39.655688312 +0100
***************
*** 4107,4112 ****
--- 4107,4153 ----
    bw!
  endfunc
  
+ def Test_multiple_funcref()
+   # This was using a NULL pointer
+   var lines =<< trim END
+       vim9script
+       def A(F: func, ...args: list<any>): func
+           return funcref(F, args)
+       enddef
+ 
+       def B(F: func): func
+           return funcref(A, [F])
+       enddef
+ 
+       def Test(n: number)
+       enddef
+ 
+       const X = B(Test)
+       X(1)
+   END
+   v9.CheckScriptSuccess(lines)
+ 
+   # slightly different case
+   lines =<< trim END
+       vim9script
+ 
+       def A(F: func, ...args: list<any>): any
+           return call(F, args)
+       enddef
+ 
+       def B(F: func): func
+           return funcref(A, [F])
+       enddef
+ 
+       def Test(n: number)
+       enddef
+ 
+       const X = B(Test)
+       X(1)
+   END
+   v9.CheckScriptSuccess(lines)
+ enddef
+ 
  " The following messes up syntax highlight, keep near the end.
  if has('python3')
    def Test_python3_command()
*** ../vim-8.2.4997/src/version.c       2022-05-22 12:23:43.271595457 +0100
--- src/version.c       2022-05-22 13:45:32.033800612 +0100
***************
*** 736,737 ****
--- 736,739 ----
  {   /* Add new patch number below this line */
+ /**/
+     4998,
  /**/

-- 
Place mark here ->[ ]<- if you want a dirty monitor.

 /// 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/20220522124754.E33231C06D7%40moolenaar.net.

Raspunde prin e-mail lui