]> granicus.if.org Git - vim/commitdiff
patch 8.1.1863: confusing error when using a builtin function as method v8.1.1863
authorBram Moolenaar <Bram@vim.org>
Fri, 16 Aug 2019 20:22:31 +0000 (22:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 16 Aug 2019 20:22:31 +0000 (22:22 +0200)
Problem:    Confusing error when using a builtin function as method while it
            does not support that.
Solution:   Add a specific error message.

src/evalfunc.c
src/testdir/test_method.vim
src/userfunc.c
src/version.c
src/vim.h

index 814499331dd4659ca83450568c916a6d83ed6715..7d46f3588662658726800e0022dfda2717bcc109 100644 (file)
@@ -1113,8 +1113,10 @@ call_internal_method(
     typval_T   argv[MAX_FUNC_ARGS + 1];
 
     fi = find_internal_func(name);
-    if (fi < 0 || global_functions[fi].f_argtype == 0)
+    if (fi < 0)
        return ERROR_UNKNOWN;
+    if (global_functions[fi].f_argtype == 0)
+       return ERROR_NOTMETHOD;
     if (argcount + 1 < global_functions[fi].f_min_argc)
        return ERROR_TOOFEW;
     if (argcount + 1 > global_functions[fi].f_max_argc)
index 98c07fe3416c8bf474d8203be70bfd6b52cab9e1..ba13bb49730d6b2bd6f2db3ea2c636306f7ba33c 100644 (file)
@@ -134,3 +134,7 @@ func Test_method_lambda()
   " todo: lambda accepts more arguments than it consumes
   " call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:')
 endfunc
+
+func Test_method_not_supported()
+  call assert_fails('eval 123->changenr()', 'E276:')
+endfunc
index 2bdc2b1cd98d3b4933985dc256f22cffa8893b4f..fd25090118cca46761c7689757dd792a56374374 100644 (file)
@@ -1678,6 +1678,11 @@ call_func(
            case ERROR_UNKNOWN:
                    emsg_funcname(N_("E117: Unknown function: %s"), name);
                    break;
+           case ERROR_NOTMETHOD:
+                   emsg_funcname(
+                              N_("E276: Cannot use function as a method: %s"),
+                                                                        name);
+                   break;
            case ERROR_DELETED:
                    emsg_funcname(N_("E933: Function was deleted: %s"), name);
                    break;
@@ -1685,15 +1690,18 @@ call_func(
                    emsg_funcname((char *)e_toomanyarg, name);
                    break;
            case ERROR_TOOFEW:
-                   emsg_funcname(N_("E119: Not enough arguments for function: %s"),
+                   emsg_funcname(
+                            N_("E119: Not enough arguments for function: %s"),
                                                                        name);
                    break;
            case ERROR_SCRIPT:
-                   emsg_funcname(N_("E120: Using <SID> not in a script context: %s"),
+                   emsg_funcname(
+                          N_("E120: Using <SID> not in a script context: %s"),
                                                                        name);
                    break;
            case ERROR_DICT:
-                   emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"),
+                   emsg_funcname(
+                     N_("E725: Calling dict function without Dictionary: %s"),
                                                                        name);
                    break;
        }
index ba37a4115672b2febe1f37e8be67f09104c47289..3adfdd059b596762c6d97a6e34b6531702ba7fd2 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1863,
 /**/
     1862,
 /**/
index 1011be7c68cb0f77a08eb94bc6b02f9fc4ba1a20..4107f6b1c7aa8c4fdfc36ba2ebab5dd4f0b7e87b 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2518,6 +2518,7 @@ typedef enum {
 #define ERROR_NONE     5
 #define ERROR_OTHER    6
 #define ERROR_DELETED  7
+#define ERROR_NOTMETHOD        8   // function cannot be used as a method
 
 /* flags for find_name_end() */
 #define FNE_INCL_BR    1       /* include [] in name */