Patch 8.2.1428
Problem:    Vim9: :def function does not abort on nested function error.
Solution:   Check whether an error message was given. (closes #6691)
Files:      src/vim9execute.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.1427/src/vim9execute.c   2020-08-12 15:21:18.966700480 +0200
--- src/vim9execute.c   2020-08-12 16:37:12.911618052 +0200
***************
*** 505,510 ****
--- 505,511 ----
      funcexe_T   funcexe;
      int               error;
      int               idx;
+     int               called_emsg_before = called_emsg;
  
      if (ufunc->uf_def_status == UF_TO_BE_COMPILED
            && compile_def_function(ufunc, FALSE, NULL) == FAIL)
***************
*** 542,547 ****
--- 543,551 ----
        user_func_error(error, ufunc->uf_name);
        return FAIL;
      }
+     if (called_emsg > called_emsg_before)
+       // Error other than from calling the function itself.
+       return FAIL;
      return OK;
  }
  
***************
*** 670,679 ****
      static int
  call_eval_func(char_u *name, int argcount, ectx_T *ectx, isn_T *iptr)
  {
!     int               called_emsg_before = called_emsg;
  
!     if (call_by_name(name, argcount, ectx, iptr) == FAIL
!                                         && called_emsg == called_emsg_before)
      {
        dictitem_T      *v;
  
--- 674,684 ----
      static int
  call_eval_func(char_u *name, int argcount, ectx_T *ectx, isn_T *iptr)
  {
!     int           called_emsg_before = called_emsg;
!     int           res;
  
!     res = call_by_name(name, argcount, ectx, iptr);
!     if (res == FAIL && called_emsg == called_emsg_before)
      {
        dictitem_T      *v;
  
***************
*** 690,696 ****
        }
        return call_partial(&v->di_tv, argcount, ectx);
      }
!     return OK;
  }
  
  /*
--- 695,701 ----
        }
        return call_partial(&v->di_tv, argcount, ectx);
      }
!     return res;
  }
  
  /*
*** ../vim-8.2.1427/src/testdir/test_vim9_script.vim    2020-08-09 
14:43:53.752239834 +0200
--- src/testdir/test_vim9_script.vim    2020-08-12 16:36:18.500070420 +0200
***************
*** 1054,1059 ****
--- 1054,1077 ----
    CheckScriptSuccess(lines)
  enddef
  
+ def Test_error_in_nested_function()
+   # an error in a nested :function aborts executin in the calling :def 
function
+   let lines =<< trim END
+       vim9script
+       def Func()
+         Error()
+         g:test_var = 1
+       enddef
+       func Error() abort
+         eval [][0]
+       endfunc
+       Func()
+   END
+   g:test_var = 0
+   CheckScriptFailure(lines, 'E684:')
+   assert_equal(0, g:test_var)
+ enddef
+ 
  def Test_cexpr_vimscript()
    # only checks line continuation
    set errorformat=File\ %f\ line\ %l
*** ../vim-8.2.1427/src/version.c       2020-08-12 15:48:51.662129295 +0200
--- src/version.c       2020-08-12 16:36:48.047822170 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1428,
  /**/

-- 
Rule #1: Don't give somebody a tool that he's going to hurt himself with.

 /// 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/202008121438.07CEch09067950%40masaka.moolenaar.net.

Raspunde prin e-mail lui