Patch 8.2.1454
Problem:    Vim9: failure invoking lambda with wrong arguments.
Solution:   Handle invalid arguments.  Add a test.
Files:      src/vim9compile.c, src/vim9execute.c,
            src/testdir/test_vim9_expr.vim


*** ../vim-8.2.1453/src/vim9compile.c   2020-08-14 21:42:50.823581047 +0200
--- src/vim9compile.c   2020-08-14 22:00:47.617823176 +0200
***************
*** 1361,1366 ****
--- 1361,1369 ----
                    continue;
                expected = ufunc->uf_arg_types[i];
            }
+           else if (ufunc->uf_va_type == NULL)
+               // possibly a lambda
+               expected = &t_any;
            else
                expected = ufunc->uf_va_type->tt_member;
            actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
*** ../vim-8.2.1453/src/vim9execute.c   2020-08-14 18:35:02.869408647 +0200
--- src/vim9execute.c   2020-08-14 22:12:46.956115012 +0200
***************
*** 206,212 ****
      arg_to_add = ufunc->uf_args.ga_len - argcount;
      if (arg_to_add < 0)
      {
!       iemsg("Argument count wrong?");
        return FAIL;
      }
      if (ga_grow(&ectx->ec_stack, arg_to_add + 3
--- 206,215 ----
      arg_to_add = ufunc->uf_args.ga_len - argcount;
      if (arg_to_add < 0)
      {
!       if (arg_to_add == -1)
!           emsg(_("E1106: one argument too many"));
!       else
!           semsg(_("E1106: %d arguments too many"), -arg_to_add);
        return FAIL;
      }
      if (ga_grow(&ectx->ec_stack, arg_to_add + 3
*** ../vim-8.2.1453/src/testdir/test_vim9_expr.vim      2020-08-14 
21:49:05.616518361 +0200
--- src/testdir/test_vim9_expr.vim      2020-08-14 22:15:05.671058605 +0200
***************
*** 1584,1589 ****
--- 1584,1597 ----
  
    call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
    call CheckDefFailure(["let L = {a -> a + b}"], 'E1001:')
+ 
+   assert_equal('xxxyyy', 'xxx'->{a, b -> a .. b}('yyy'))
+ 
+   CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x')"],
+         'E1106: one argument too many')
+   CheckDefExecFailure(["let s = 'asdf'->{a -> a}('x', 'y')"],
+         'E1106: 2 arguments too many')
+   CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:')
  enddef
  
  def Test_expr7_lambda_vim9script()
*** ../vim-8.2.1453/src/version.c       2020-08-14 21:49:05.620518318 +0200
--- src/version.c       2020-08-14 22:15:39.158804703 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1454,
  /**/

-- 
panic("Foooooooood fight!");
        -- In the kernel source aha1542.c, after detecting a bad segment list

 /// Bram Moolenaar -- b...@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    ///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202008142017.07EKH9tR144202%40masaka.moolenaar.net.

Raspunde prin e-mail lui