Patch 8.2.3720
Problem:    Vim9: Internal error when invoking closure in legacy context.
Solution:   Give a more appropriate error message. (closes #9251)
Files:      src/errors.h, src/vim9execute.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.3719/src/errors.h        2021-11-30 16:14:44.056582159 +0000
--- src/errors.h        2021-12-02 15:06:50.547934990 +0000
***************
*** 689,691 ****
--- 689,693 ----
        INIT(= N_("E1246: Cannot find variable to (un)lock: %s"));
  EXTERN char e_line_number_out_of_range[]
        INIT(= N_("E1247: Line number out of range"));
+ EXTERN char e_closure_called_from_invalid_context[]
+       INIT(= N_("E1248: Closure called from invalid context"));
*** ../vim-8.2.3719/src/vim9execute.c   2021-12-01 15:22:53.106902067 +0000
--- src/vim9execute.c   2021-12-02 15:05:59.500322622 +0000
***************
*** 2733,2739 ****
                    if (outer == NULL)
                    {
                        SOURCING_LNUM = iptr->isn_lnum;
!                       iemsg("LOADOUTER depth more than scope levels");
                        goto theend;
                    }
                    tv = ((typval_T *)outer->out_stack->ga_data)
--- 2733,2745 ----
                    if (outer == NULL)
                    {
                        SOURCING_LNUM = iptr->isn_lnum;
!                       if (ectx->ec_frame_idx == ectx->ec_initial_frame_idx
!                                                || ectx->ec_outer_ref == NULL)
!                           // Possibly :def function called from legacy
!                           // context.
!                           emsg(_(e_closure_called_from_invalid_context));
!                       else
!                           iemsg("LOADOUTER depth more than scope levels");
                        goto theend;
                    }
                    tv = ((typval_T *)outer->out_stack->ga_data)
*** ../vim-8.2.3719/src/testdir/test_vim9_func.vim      2021-11-28 
22:00:08.152081403 +0000
--- src/testdir/test_vim9_func.vim      2021-12-02 15:12:49.401883534 +0000
***************
*** 2384,2389 ****
--- 2384,2404 ----
    delfunc g:Inner
  enddef
  
+ def Test_closure_called_from_legacy()
+   var lines =<< trim END
+       vim9script
+       def Func()
+         var outer = 'foo'
+         var F = () => {
+               outer = 'bar'
+             }
+         execute printf('call %s()', string(F))
+       enddef
+       Func()
+   END
+   CheckScriptFailure(lines, 'E1248')
+ enddef
+ 
  def Test_failure_in_called_function()
    # this was using the frame index as the return value
    var lines =<< trim END
*** ../vim-8.2.3719/src/version.c       2021-12-02 12:30:17.417741511 +0000
--- src/version.c       2021-12-02 15:08:09.999387813 +0000
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     3720,
  /**/

-- 
Westheimer's Discovery:
        A couple of months in the laboratory can
        frequently save a couple of hours in the library.

 /// 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/20211202164015.116861C28D5%40moolenaar.net.

Raspunde prin e-mail lui