Patch 8.2.4657
Problem:    Errors for functions are sometimes hard to read.
Solution:   Use printable_func_name() in more places.
Files:      src/vim9execute.c, src/userfunc.c, src/proto/userfunc.pro,
            src/vim9expr.c, src/eval.c, src/vim9instr.c, src/vim9type.c,
            src/testdir/test_vim9_expr.vim


*** ../vim-8.2.4656/src/vim9execute.c   2022-03-31 10:13:44.130427942 +0100
--- src/vim9execute.c   2022-03-31 19:27:20.565122962 +0100
***************
*** 1012,1021 ****
        if (error != FCERR_UNKNOWN)
        {
            if (error == FCERR_TOOMANY)
!               semsg(_(e_too_many_arguments_for_function_str), ufunc->uf_name);
            else
                semsg(_(e_not_enough_arguments_for_function_str),
!                                                              ufunc->uf_name);
            return FAIL;
        }
  
--- 1012,1022 ----
        if (error != FCERR_UNKNOWN)
        {
            if (error == FCERR_TOOMANY)
!               semsg(_(e_too_many_arguments_for_function_str),
!                                                  printable_func_name(ufunc));
            else
                semsg(_(e_not_enough_arguments_for_function_str),
!                                                  printable_func_name(ufunc));
            return FAIL;
        }
  
***************
*** 1047,1053 ****
  
      if (error != FCERR_NONE)
      {
!       user_func_error(error, ufunc->uf_name, &funcexe);
        return FAIL;
      }
      if (did_emsg > did_emsg_before)
--- 1048,1054 ----
  
      if (error != FCERR_NONE)
      {
!       user_func_error(error, printable_func_name(ufunc), &funcexe);
        return FAIL;
      }
      if (did_emsg > did_emsg_before)
***************
*** 1211,1217 ****
      if (res == FAIL)
      {
        if (called_emsg == called_emsg_before)
!           semsg(_(e_unknown_function_str),
                                  name == NULL ? (char_u *)"[unknown]" : name);
        return FAIL;
      }
--- 1212,1218 ----
      if (res == FAIL)
      {
        if (called_emsg == called_emsg_before)
!           emsg_funcname(e_unknown_function_str,
                                  name == NULL ? (char_u *)"[unknown]" : name);
        return FAIL;
      }
***************
*** 1570,1583 ****
        dictitem_T      *v;
  
        v = find_var(name, NULL, FALSE);
!       if (v == NULL)
        {
!           semsg(_(e_unknown_function_str), name);
!           return FAIL;
!       }
!       if (v->di_tv.v_type != VAR_PARTIAL && v->di_tv.v_type != VAR_FUNC)
!       {
!           semsg(_(e_unknown_function_str), name);
            return FAIL;
        }
        return call_partial(&v->di_tv, argcount, ectx);
--- 1571,1580 ----
        dictitem_T      *v;
  
        v = find_var(name, NULL, FALSE);
!       if (v == NULL || (v->di_tv.v_type != VAR_PARTIAL
!                                              && v->di_tv.v_type != VAR_FUNC))
        {
!           emsg_funcname(e_unknown_function_str, name);
            return FAIL;
        }
        return call_partial(&v->di_tv, argcount, ectx);
*** ../vim-8.2.4656/src/userfunc.c      2022-03-30 21:12:16.451923056 +0100
--- src/userfunc.c      2022-03-31 19:22:19.493849374 +0100
***************
*** 527,532 ****
--- 527,554 ----
  }
  
  /*
+  * If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough
+  * return "buf" filled with a readable function name.
+  * Otherwise just return "name", thus the return value can always be used.
+  * "name" and "buf" may be equal.
+  */
+     char_u *
+ make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize)
+ {
+     size_t len;
+ 
+     if (name[0] != K_SPECIAL)
+       return name;
+     len = STRLEN(name);
+     if (len + 3 > bufsize)
+       return name;
+ 
+     mch_memmove(buf + 5, name + 3, len + 1);
+     mch_memmove(buf, "<SNR>", 5);
+     return buf;
+ }
+ 
+ /*
   * Get a name for a lambda.  Returned in static memory.
   */
      char_u *
***************
*** 3354,3366 ****
      {
        case FCERR_UNKNOWN:
                if (funcexe->fe_found_var)
!                   semsg(_(e_not_callable_type_str), name);
                else
                    emsg_funcname(e_unknown_function_str, name);
                break;
        case FCERR_NOTMETHOD:
!               emsg_funcname(
!                       N_(e_cannot_use_function_as_method_str), name);
                break;
        case FCERR_DELETED:
                emsg_funcname(e_function_was_deleted_str, name);
--- 3376,3387 ----
      {
        case FCERR_UNKNOWN:
                if (funcexe->fe_found_var)
!                   emsg_funcname(e_not_callable_type_str, name);
                else
                    emsg_funcname(e_unknown_function_str, name);
                break;
        case FCERR_NOTMETHOD:
!               emsg_funcname(e_cannot_use_function_as_method_str, name);
                break;
        case FCERR_DELETED:
                emsg_funcname(e_function_was_deleted_str, name);
***************
*** 3372,3379 ****
                emsg_funcname(e_not_enough_arguments_for_function_str, name);
                break;
        case FCERR_SCRIPT:
!               emsg_funcname(
!                   e_using_sid_not_in_script_context_str, name);
                break;
        case FCERR_DICT:
                emsg_funcname(e_calling_dict_function_without_dictionary_str,
--- 3393,3399 ----
                emsg_funcname(e_not_enough_arguments_for_function_str, name);
                break;
        case FCERR_SCRIPT:
!               emsg_funcname(e_using_sid_not_in_script_context_str, name);
                break;
        case FCERR_DICT:
                emsg_funcname(e_calling_dict_function_without_dictionary_str,
***************
*** 3613,3621 ****
       * cancelled due to an aborting error, an interrupt, or an exception.
       */
      if (!aborting())
-     {
        user_func_error(error, (name != NULL) ? name : funcname, funcexe);
-     }
  
      // clear the copies made from the partial
      while (argv_clear > 0)
--- 3633,3639 ----
*** ../vim-8.2.4656/src/proto/userfunc.pro      2022-03-30 21:12:16.451923056 
+0100
--- src/proto/userfunc.pro      2022-03-31 19:21:11.722027885 +0100
***************
*** 1,6 ****
--- 1,7 ----
  /* userfunc.c */
  void func_init(void);
  hashtab_T *func_tbl_get(void);
+ char_u *make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize);
  char_u *get_lambda_name(void);
  char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
  int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, 
evalarg_T *evalarg);
*** ../vim-8.2.4656/src/vim9expr.c      2022-03-31 16:18:19.916278625 +0100
--- src/vim9expr.c      2022-03-31 19:20:37.058121940 +0100
***************
*** 698,704 ****
      char_u    *name = *arg;
      char_u    *p;
      int               argcount = argcount_init;
!     char_u    namebuf[100];
      char_u    fname_buf[FLEN_FIXED + 1];
      char_u    *tofree = NULL;
      int               error = FCERR_NONE;
--- 698,704 ----
      char_u    *name = *arg;
      char_u    *p;
      int               argcount = argcount_init;
!     char_u    namebuf[MAX_FUNC_NAME_LEN];
      char_u    fname_buf[FLEN_FIXED + 1];
      char_u    *tofree = NULL;
      int               error = FCERR_NONE;
***************
*** 818,824 ****
                res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
        }
        else
!           semsg(_(e_unknown_function_str), namebuf);
        goto theend;
      }
  
--- 818,824 ----
                res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
        }
        else
!           emsg_funcname(e_unknown_function_str, namebuf);
        goto theend;
      }
  
***************
*** 843,849 ****
                          && vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL)
            {
                // A function name without g: prefix must be found locally.
!               semsg(_(e_unknown_function_str), namebuf);
                goto theend;
            }
        }
--- 843,849 ----
                          && vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL)
            {
                // A function name without g: prefix must be found locally.
!               emsg_funcname(e_unknown_function_str, namebuf);
                goto theend;
            }
        }
***************
*** 874,880 ****
      if (has_g_namespace || is_autoload)
        res = generate_UCALL(cctx, name, argcount);
      else
!       semsg(_(e_unknown_function_str), namebuf);
  
  theend:
      vim_free(tofree);
--- 874,880 ----
      if (has_g_namespace || is_autoload)
        res = generate_UCALL(cctx, name, argcount);
      else
!       emsg_funcname(e_unknown_function_str, namebuf);
  
  theend:
      vim_free(tofree);
*** ../vim-8.2.4656/src/eval.c  2022-03-25 11:16:24.932035331 +0000
--- src/eval.c  2022-03-31 19:01:21.884067030 +0100
***************
*** 5296,5310 ****
            break;
  
        case VAR_FUNC:
-           if (echo_style)
            {
!               *tofree = NULL;
!               r = tv->vval.v_string;
!           }
!           else
!           {
!               *tofree = string_quote(tv->vval.v_string, TRUE);
!               r = *tofree;
            }
            break;
  
--- 5296,5324 ----
            break;
  
        case VAR_FUNC:
            {
!               char_u buf[MAX_FUNC_NAME_LEN];
! 
!               if (echo_style)
!               {
!                   r = make_ufunc_name_readable(tv->vval.v_string,
!                                                      buf, MAX_FUNC_NAME_LEN);
!                   if (r == buf)
!                   {
!                       r = vim_strsave(buf);
!                       *tofree = r;
!                   }
!                   else
!                       *tofree = NULL;
!               }
!               else
!               {
!                   *tofree = string_quote(tv->vval.v_string == NULL ? NULL
!                           : make_ufunc_name_readable(
!                               tv->vval.v_string, buf, MAX_FUNC_NAME_LEN),
!                                                                        TRUE);
!                   r = *tofree;
!               }
            }
            break;
  
*** ../vim-8.2.4656/src/vim9instr.c     2022-03-31 16:18:19.916278625 +0100
--- src/vim9instr.c     2022-03-31 19:32:06.992498559 +0100
***************
*** 1517,1523 ****
      }
      if (ufunc->uf_def_status == UF_COMPILE_ERROR)
      {
!       emsg_funcname(_(e_call_to_function_that_failed_to_compile_str),
                                                               ufunc->uf_name);
        return FAIL;
      }
--- 1517,1523 ----
      }
      if (ufunc->uf_def_status == UF_COMPILE_ERROR)
      {
!       emsg_funcname(e_call_to_function_that_failed_to_compile_str,
                                                               ufunc->uf_name);
        return FAIL;
      }
***************
*** 1594,1605 ****
  
            if (argcount < type->tt_min_argcount - varargs)
            {
!               semsg(_(e_not_enough_arguments_for_function_str), name);
                return FAIL;
            }
            if (!varargs && argcount > type->tt_argcount)
            {
!               semsg(_(e_too_many_arguments_for_function_str), name);
                return FAIL;
            }
            if (type->tt_args != NULL)
--- 1594,1605 ----
  
            if (argcount < type->tt_min_argcount - varargs)
            {
!               emsg_funcname(e_not_enough_arguments_for_function_str, name);
                return FAIL;
            }
            if (!varargs && argcount > type->tt_argcount)
            {
!               emsg_funcname(e_too_many_arguments_for_function_str, name);
                return FAIL;
            }
            if (type->tt_args != NULL)
*** ../vim-8.2.4656/src/vim9type.c      2022-03-28 15:22:31.486443735 +0100
--- src/vim9type.c      2022-03-31 19:32:24.228462367 +0100
***************
*** 780,791 ****
        return OK;  // just in case
      if (totcount < type->tt_min_argcount - varargs)
      {
!       semsg(_(e_not_enough_arguments_for_function_str), name);
        return FAIL;
      }
      if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount)
      {
!       semsg(_(e_too_many_arguments_for_function_str), name);
        return FAIL;
      }
      if (type->tt_args == NULL)
--- 780,791 ----
        return OK;  // just in case
      if (totcount < type->tt_min_argcount - varargs)
      {
!       emsg_funcname(e_not_enough_arguments_for_function_str, name);
        return FAIL;
      }
      if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount)
      {
!       emsg_funcname(e_too_many_arguments_for_function_str, name);
        return FAIL;
      }
      if (type->tt_args == NULL)
*** ../vim-8.2.4656/src/testdir/test_vim9_expr.vim      2022-03-28 
15:22:31.490443719 +0100
--- src/testdir/test_vim9_expr.vim      2022-03-31 18:48:14.336211247 +0100
***************
*** 4010,4016 ****
    call v9.CheckDefFailure(["echo len('asdf'"], 'E110:', 2)
    call v9.CheckScriptFailure(['vim9script', "echo len('asdf'"], 'E116:', 2)
  
!   call v9.CheckDefAndScriptFailure(["echo 
Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"],
 ['E1011:', 'E117:'], 1)
    call v9.CheckDefAndScriptFailure(["echo doesnotexist()"], 'E117:', 1)
  endfunc
  
--- 4010,4016 ----
    call v9.CheckDefFailure(["echo len('asdf'"], 'E110:', 2)
    call v9.CheckScriptFailure(['vim9script', "echo len('asdf'"], 'E116:', 2)
  
!   call v9.CheckDefAndScriptFailure(["echo 
Func01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"],
 ['E1011:', 'E117:'], 1)
    call v9.CheckDefAndScriptFailure(["echo doesnotexist()"], 'E117:', 1)
  endfunc
  
*** ../vim-8.2.4656/src/version.c       2022-03-31 16:18:19.916278625 +0100
--- src/version.c       2022-03-31 18:01:01.609105034 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4657,
  /**/

-- 
In Africa some of the native tribes have a custom of beating the ground
with clubs and uttering spine chilling cries.  Anthropologists call
this a form of primitive self-expression.  In America we call it golf.

 /// 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/20220331190333.02C1D1C13F2%40moolenaar.net.

Raspunde prin e-mail lui