mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1527: Vim9: cannot use a function name at script level
Problem: Vim9: cannot use a function name as a function reference at script level. Solution: Check if a name is a function name. (closes #6789)
This commit is contained in:
@@ -2461,6 +2461,20 @@ eval_variable(
|
|||||||
tv = sv->sv_tv;
|
tv = sv->sv_tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (in_vim9script())
|
||||||
|
{
|
||||||
|
ufunc_T *ufunc = find_func(name, FALSE, NULL);
|
||||||
|
|
||||||
|
if (ufunc != NULL)
|
||||||
|
{
|
||||||
|
foundFunc = TRUE;
|
||||||
|
if (rettv != NULL)
|
||||||
|
{
|
||||||
|
rettv->v_type = VAR_FUNC;
|
||||||
|
rettv->vval.v_string = vim_strsave(ufunc->uf_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundFunc)
|
if (!foundFunc)
|
||||||
|
@@ -1668,6 +1668,17 @@ def Test_expr7_lambda_vim9script()
|
|||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_epxr7_funcref()
|
||||||
|
let lines =<< trim END
|
||||||
|
def RetNumber(): number
|
||||||
|
return 123
|
||||||
|
enddef
|
||||||
|
let FuncRef = RetNumber
|
||||||
|
assert_equal(123, FuncRef())
|
||||||
|
END
|
||||||
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_expr7_dict()
|
def Test_expr7_dict()
|
||||||
# dictionary
|
# dictionary
|
||||||
assert_equal(g:dict_empty, {})
|
assert_equal(g:dict_empty, {})
|
||||||
|
@@ -1684,8 +1684,9 @@ def Test_vim9script_funcref()
|
|||||||
delete('Xscript.vim')
|
delete('Xscript.vim')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Check that when searcing for "FilterFunc" it doesn't find the import in the
|
" Check that when searching for "FilterFunc" it finds the import in the
|
||||||
" script where FastFilter() is called from.
|
" script where FastFilter() is called from, both as a string and as a direct
|
||||||
|
" function reference.
|
||||||
def Test_vim9script_funcref_other_script()
|
def Test_vim9script_funcref_other_script()
|
||||||
let filterLines =<< trim END
|
let filterLines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@@ -1695,22 +1696,26 @@ def Test_vim9script_funcref_other_script()
|
|||||||
export def FastFilter(): list<number>
|
export def FastFilter(): list<number>
|
||||||
return range(10)->filter('FilterFunc')
|
return range(10)->filter('FilterFunc')
|
||||||
enddef
|
enddef
|
||||||
|
export def FastFilterDirect(): list<number>
|
||||||
|
return range(10)->filter(FilterFunc)
|
||||||
|
enddef
|
||||||
END
|
END
|
||||||
writefile(filterLines, 'Xfilter.vim')
|
writefile(filterLines, 'Xfilter.vim')
|
||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
import {FilterFunc, FastFilter} from './Xfilter.vim'
|
import {FilterFunc, FastFilter, FastFilterDirect} from './Xfilter.vim'
|
||||||
def Test()
|
def Test()
|
||||||
let x: list<number> = FastFilter()
|
let x: list<number> = FastFilter()
|
||||||
enddef
|
enddef
|
||||||
Test()
|
Test()
|
||||||
|
def TestDirect()
|
||||||
|
let x: list<number> = FastFilterDirect()
|
||||||
|
enddef
|
||||||
|
TestDirect()
|
||||||
END
|
END
|
||||||
writefile(lines, 'Ximport.vim')
|
CheckScriptSuccess(lines)
|
||||||
assert_fails('source Ximport.vim', 'E121:')
|
|
||||||
|
|
||||||
delete('Xfilter.vim')
|
delete('Xfilter.vim')
|
||||||
delete('Ximport.vim')
|
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_vim9script_reload_delfunc()
|
def Test_vim9script_reload_delfunc()
|
||||||
|
@@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1527,
|
||||||
/**/
|
/**/
|
||||||
1526,
|
1526,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user