1
0
forked from aniani/vim

patch 9.0.0219: cannot make a funcref with "s:func" in a def function

Problem:    Cannot make a funcref with "s:func" in a def function in legacy
            script.
Solution:   Allow for using a lower case function name after "s:". (Kota Kato,
            closes #10926)
This commit is contained in:
Kota Kato
2022-08-16 16:09:59 +01:00
committed by Bram Moolenaar
parent e98c88c44c
commit 948a3894d9
4 changed files with 45 additions and 4 deletions

View File

@@ -1957,6 +1957,45 @@ def Test_call_funcref()
g:listarg->assert_equal([1, 2, 3]) g:listarg->assert_equal([1, 2, 3])
END END
v9.CheckScriptSuccess(lines) v9.CheckScriptSuccess(lines)
lines =<< trim END
function s:func(num)
return a:num * 2
endfunction
def s:CallFuncref()
var Funcref = function('s:func')
Funcref(3)->assert_equal(6)
enddef
call s:CallFuncref()
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
function s:func(num)
return a:num * 2
endfunction
def s:CallFuncref()
var Funcref = function(s:func)
Funcref(3)->assert_equal(6)
enddef
call s:CallFuncref()
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
function s:func(num)
return a:num * 2
endfunction
def s:CallFuncref()
var Funcref = s:func
Funcref(3)->assert_equal(6)
enddef
call s:CallFuncref()
END
v9.CheckScriptSuccess(lines)
enddef enddef
let SomeFunc = function('len') let SomeFunc = function('len')

View File

@@ -3995,7 +3995,8 @@ trans_function_name(
{ {
if (!vim9_local) if (!vim9_local)
{ {
if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)) if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)
&& current_script_is_vim9())
{ {
semsg(_(e_function_name_must_start_with_capital_str), start); semsg(_(e_function_name_must_start_with_capital_str), start);
goto theend; goto theend;

View File

@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
219,
/**/ /**/
218, 218,
/**/ /**/

View File

@@ -8,7 +8,7 @@
*/ */
/* /*
* vim9cmds.c: Dealing with compiled function expressions * vim9expr.c: Dealing with compiled function expressions
*/ */
#define USING_FLOAT_STUFF #define USING_FLOAT_STUFF
@@ -451,8 +451,7 @@ compile_load(
vim_free(name); vim_free(name);
return FAIL; return FAIL;
} }
if (is_expr && ASCII_ISUPPER(*name) if (is_expr && find_func(name, FALSE) != NULL)
&& find_func(name, FALSE) != NULL)
res = generate_funcref(cctx, name, FALSE); res = generate_funcref(cctx, name, FALSE);
else else
res = compile_load_scriptvar(cctx, name, res = compile_load_scriptvar(cctx, name,