aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-07 15:10:28 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-08-12 22:35:23 +0100
commit98dfe4adc48d83e05b2ee039869853760de9c096 (patch)
tree8855847ce03f092156ac7770b615598e43ffbaff
parent287a77ef51a7a12813d3fa6e1c49c595e5951ba5 (diff)
downloadrneovim-98dfe4adc48d83e05b2ee039869853760de9c096.tar.gz
rneovim-98dfe4adc48d83e05b2ee039869853760de9c096.tar.bz2
rneovim-98dfe4adc48d83e05b2ee039869853760de9c096.zip
vim-patch:8.1.1863: confusing error when using a builtin function as method
Problem: Confusing error when using a builtin function as method while it does not support that. Solution: Add a specific error message. https://github.com/vim/vim/commit/9174639a82799011cfa0013cbc4c4709b3833bf0
-rw-r--r--src/nvim/eval/funcs.c4
-rw-r--r--src/nvim/eval/userfunc.c3
-rw-r--r--src/nvim/eval/userfunc.h1
-rw-r--r--src/nvim/testdir/test_method.vim4
4 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index e090f3b37f..8a1258efd4 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -199,8 +199,10 @@ int call_internal_method(const char_u *const fname, const int argcount,
FUNC_ATTR_NONNULL_ALL
{
const VimLFuncDef *const fdef = find_internal_func((const char *)fname);
- if (fdef == NULL || fdef->base_arg == BASE_NONE) {
+ if (fdef == NULL) {
return ERROR_UNKNOWN;
+ } else if (fdef->base_arg == BASE_NONE) {
+ return ERROR_NOTMETHOD;
} else if (argcount + 1 < fdef->min_argc) {
return ERROR_TOOFEW;
} else if (argcount + 1 > fdef->max_argc) {
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 9ecde327de..59f07ff486 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -1399,6 +1399,9 @@ static void user_func_error(int error, const char_u *name)
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;
diff --git a/src/nvim/eval/userfunc.h b/src/nvim/eval/userfunc.h
index 513473449a..3f111343d2 100644
--- a/src/nvim/eval/userfunc.h
+++ b/src/nvim/eval/userfunc.h
@@ -28,6 +28,7 @@ typedef enum {
ERROR_OTHER,
ERROR_BOTH,
ERROR_DELETED,
+ ERROR_NOTMETHOD,
} FnameTransError;
/// Used in funcexe_T. Returns the new argcount.
diff --git a/src/nvim/testdir/test_method.vim b/src/nvim/testdir/test_method.vim
index eeb90cd16a..f08ca4e7f1 100644
--- a/src/nvim/testdir/test_method.vim
+++ b/src/nvim/testdir/test_method.vim
@@ -140,4 +140,8 @@ func Test_method_lambda()
" call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:')
endfunc
+func Test_method_not_supported()
+ call assert_fails('eval 123->changenr()', 'E276:')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab