1
0
forked from aniani/vim

patch 9.0.0366: cannot use import->Func() in lambda

Problem:    Cannot use import->Func() in lambda. (Israel Chauca Fuentes)
Solution:   Adjust how an expression in a lambda is parsed. (closes #11042)
This commit is contained in:
Bram Moolenaar 2022-09-03 12:09:07 +01:00
parent 91a874eb88
commit 6ac69ed9a2
3 changed files with 41 additions and 3 deletions

View File

@ -694,8 +694,15 @@ deref_function_name(
{ {
typval_T ref; typval_T ref;
char_u *name = *arg; char_u *name = *arg;
int save_flags;
ref.v_type = VAR_UNKNOWN; ref.v_type = VAR_UNKNOWN;
if (evalarg != NULL)
{
// need to evaluate this to get an import, like in "a.Func"
save_flags = evalarg->eval_flags;
evalarg->eval_flags |= EVAL_EVALUATE;
}
if (eval9(arg, &ref, evalarg, FALSE) == FAIL) if (eval9(arg, &ref, evalarg, FALSE) == FAIL)
{ {
dictitem_T *v; dictitem_T *v;
@ -703,7 +710,10 @@ deref_function_name(
// If <SID>VarName was used it would not be found, try another way. // If <SID>VarName was used it would not be found, try another way.
v = find_var_also_in_script(name, NULL, FALSE); v = find_var_also_in_script(name, NULL, FALSE);
if (v == NULL) if (v == NULL)
return NULL; {
name = NULL;
goto theend;
}
copy_tv(&v->di_tv, &ref); copy_tv(&v->di_tv, &ref);
} }
if (*skipwhite(*arg) != NUL) if (*skipwhite(*arg) != NUL)
@ -739,7 +749,11 @@ deref_function_name(
semsg(_(e_not_callable_type_str), name); semsg(_(e_not_callable_type_str), name);
name = NULL; name = NULL;
} }
theend:
clear_tv(&ref); clear_tv(&ref);
if (evalarg != NULL)
evalarg->eval_flags = save_flags;
return name; return name;
} }
@ -4080,7 +4094,7 @@ eval9(
// Handle following '[', '(' and '.' for expr[expr], expr.name, // Handle following '[', '(' and '.' for expr[expr], expr.name,
// expr(expr), expr->name(expr) // expr(expr), expr->name(expr)
if (ret == OK) if (ret == OK)
ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE); ret = handle_subscript(arg, name_start, rettv, evalarg, evaluate);
/* /*
* Apply logical NOT and unary '-', from right to left, ignore '+'. * Apply logical NOT and unary '-', from right to left, ignore '+'.
@ -4349,7 +4363,7 @@ eval_method(
rettv->v_type = VAR_UNKNOWN; rettv->v_type = VAR_UNKNOWN;
name = *arg; name = *arg;
len = get_name_len(arg, &alias, evaluate, TRUE); len = get_name_len(arg, &alias, evaluate, evaluate);
if (alias != NULL) if (alias != NULL)
name = alias; name = alias;

View File

@ -1454,6 +1454,28 @@ def Run_Test_import_in_spellsuggest_expr()
set nospell spellsuggest& verbose=0 set nospell spellsuggest& verbose=0
enddef enddef
def Test_import_in_lambda_method()
var lines =<< trim END
vim9script
export def Retarg(e: any): any
return e
enddef
END
writefile(lines, 'XexportRetarg.vim')
lines =<< trim END
vim9script
import './XexportRetarg.vim'
def Lambda(): string
var F = (x) => x->XexportRetarg.Retarg()
return F('arg')
enddef
assert_equal('arg', Lambda())
END
v9.CheckScriptSuccess(lines)
delete('XexportRetarg.vim')
enddef
def Test_export_shadows_global_function() def Test_export_shadows_global_function()
mkdir('Xglobdir/autoload', 'p') mkdir('Xglobdir/autoload', 'p')
var save_rtp = &rtp var save_rtp = &rtp

View File

@ -707,6 +707,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 */
/**/
366,
/**/ /**/
365, 365,
/**/ /**/