From da9005af792f7a7eaae98ee9f6499af9a97fd095 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 12 Aug 2021 17:19:05 +0100 Subject: [PATCH] fix(v:lua): fix emsg when calling v:lua directly v:lua expressions are represented using vvlua_partial. As v:lua isn't intended to be called directly, it's given an empty pt_name. Because of this, calling v:lua directly like "v:lua()" will cause "E117: Unknown function: ", with an empty name. Instead, have call_func() show the name "v:lua" in the emsg. --- src/nvim/eval/userfunc.c | 4 ++++ test/functional/lua/luaeval_spec.lua | 1 + 2 files changed, 5 insertions(+) diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 4f10d31615..5ffd578891 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1516,6 +1516,10 @@ call_func( if (len > 0) { error = ERROR_NONE; nlua_typval_call((const char *)funcname, len, argvars, argcount, rettv); + } else { + // v:lua was called directly; show its name in the emsg + XFREE_CLEAR(name); + funcname = (const char_u *)"v:lua"; } } else if (fp != NULL || !builtin_function((const char *)rfname, -1)) { // User defined function. diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 2ec48777fd..263408ad33 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -518,6 +518,7 @@ describe('v:lua', function() eq("Vim:E15: Invalid expression: v:['lua'].foo()", pcall_err(eval, "v:['lua'].foo()")) eq("Vim(call):E461: Illegal variable name: v:['lua']", pcall_err(command, "call v:['lua'].baar()")) + eq("Vim:E117: Unknown function: v:lua", pcall_err(eval, "v:lua()")) eq("Vim(let):E46: Cannot change read-only variable \"v:['lua']\"", pcall_err(command, "let v:['lua'] = 'xx'")) eq("Vim(let):E46: Cannot change read-only variable \"v:lua\"", pcall_err(command, "let v:lua = 'xx'"))