----------------------------------------
let s:f = function('type')
let s:fref = function('s:f')
" => <SNR>1_f
echo call(s:fref, ['x'])
" => E117: Unknown function: <SNR>1_f
----------------------------------------
In this script, function('s:f') should be an error.
----------------------------------------
let s:fref = function('s:f')
----------------------------------------
diff -r 2a798dca16bf src/eval.c
--- a/src/eval.c Wed Aug 06 19:09:16 2014 +0200
+++ b/src/eval.c Thu Aug 07 14:01:26 2014 +0900
@@ -157,6 +157,7 @@
#define TFN_INT 1 /* internal function name OK */
#define TFN_QUIET 2 /* no error messages */
#define TFN_NO_AUTOLOAD 4 /* do not use script autoloading */
+#define TFN_NO_DEREF 8 /* do not deref function reference */
/* Values for get_lval() flags argument: */
#define GLV_QUIET TFN_QUIET /* no error messages */
@@ -22450,6 +22451,7 @@
* TFN_INT: internal function name OK
* TFN_QUIET: be quiet
* TFN_NO_AUTOLOAD: do not use script autoloading
+ * TFN_NO_DEREF: do not deref function reference
* Advances "pp" to just after the function name (if no error).
*/
static char_u *
@@ -22554,7 +22556,7 @@
if (name == lv.ll_exp_name)
name = NULL;
}
- else
+ else if (flags & TFN_NO_DEREF == 0)
{
len = (int)(end - *pp);
name = deref_func_name(*pp, &len, flags & TFN_NO_AUTOLOAD);
@@ -22786,8 +22788,8 @@
char_u *p;
int n = FALSE;
- p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET|TFN_NO_AUTOLOAD,
- NULL);
+ p = trans_function_name(&nm, FALSE,
+ TFN_INT|TFN_QUIET|TFN_NO_AUTOLOAD|TFN_NO_DEREF, NULL);
nm = skipwhite(nm);
/* Only accept "funcname", "funcname ", "funcname (..." and
In testdir/test_eval_func.vim
-------------
func! s:Testje()
return "foo"
endfunc
let Bar = function('s:Testje')
$put ='func Bar exists: ' . exists('*Bar')
-------------
This should be: "func Bar exists: 0"
-------------------------
function! s:type(x)
return a:x
endfunction
let s:type = function('type')
" => E705
-------------------------
function! Type(x)
return a:x
endfunction
let Type = function('type')
" => E705
-------------------------
function! s:type(x)
return a:x
endfunction
let s:type = 0
echo s:type('x')
" => 'x'
-------------------------
let s:type = function('type')
function! s:type(x)
return a:x
endfunction
echo s:type('x')
" => 1
-------------------------
let s:type = function('type')
function! s:type(x)
return a:x
endfunction
let s:type = function('type')
echo s:type('x')
" => 1
2014/8/7 Thu 14:22:32 UTC+9 mattn wrote:
> Hi list.
>
> ----------------------------------------
> let s:f = function('type')
> let s:fref = function('s:f')
> " => <SNR>1_f
> echo call(s:fref, ['x'])
> " => E117: Unknown function: <SNR>1_f
> ----------------------------------------
>
> In this script, function('s:f') should be an error.
>
> ----------------------------------------
> let s:fref = function('s:f')
> ----------------------------------------
How about this patch?
https://bitbucket.org/k_takata/vim-ktakata-mq/src/535170f9175dbfd922535d585a4b63736329b209/function-noderef.patch?at=default
This doesn't break existing tests.
I'm not sure which file should I add new tests for this to.
Regards,
Ken Takata
2016/7/23 Sat 21:01:44 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
>
> > 2014/8/7 Thu 14:22:32 UTC+9 mattn wrote:
> > > Hi list.
> > >
> > > ----------------------------------------
> > > let s:f = function('type')
> > > let s:fref = function('s:f')
> > > " => <SNR>1_f
> > > echo call(s:fref, ['x'])
> > > " => E117: Unknown function: <SNR>1_f
> > > ----------------------------------------
> > >
> > > In this script, function('s:f') should be an error.
> > >
> > > ----------------------------------------
> > > let s:fref = function('s:f')
> > > ----------------------------------------
> >
> > How about this patch?
> > https://bitbucket.org/k_takata/vim-ktakata-mq/src/535170f9175dbfd922535d585a4b63736329b209/function-noderef.patch?at=default
> >
> > This doesn't break existing tests.
> > I'm not sure which file should I add new tests for this to.
>
> I think test_expr.vim is a good place. But perhaps this test also needs
> to include another script to check passing a script-local function in a
> funcref to another script?
I added very simple test.
* function(s:f) works, but
* function('s:f') causes an error.
Please check the following patch:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/95e9a10fea18993f6dcc710364c2908acb1e2caa/function-noderef.patch?at=default
Regards,
Ken Takata