Mercurial > vim
diff src/eval.c @ 23527:27ca5534a408 v8.2.2306
patch 8.2.2306: Vim9: when using function reference type is not checked
Commit: https://github.com/vim/vim/commit/32b3f820107139d7edf0c592bb06f090c3eb6c51
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 6 21:59:39 2021 +0100
patch 8.2.2306: Vim9: when using function reference type is not checked
Problem: Vim9: when using function reference type is not checked.
Solution: When using a function reference lookup the type and check the
argument types. (issue #7629)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 06 Jan 2021 22:00:06 +0100 |
parents | 54ec7c8b7459 |
children | 1bb7fa4f9b35 |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -721,8 +721,10 @@ call_func_retlist( #ifdef FEAT_FOLDING /* - * Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding - * it in "*cp". Doesn't give error messages. + * Evaluate "arg", which is 'foldexpr'. + * Note: caller must set "curwin" to match "arg". + * Returns the foldlevel, and any character preceding it in "*cp". Doesn't + * give error messages. */ int eval_foldexpr(char_u *arg, int *cp) @@ -809,6 +811,7 @@ get_lval( int len; hashtab_T *ht = NULL; int quiet = flags & GLV_QUIET; + int writing; // Clear everything in "lp". CLEAR_POINTER(lp); @@ -882,10 +885,10 @@ get_lval( cc = *p; *p = NUL; - // Only pass &ht when we would write to the variable, it prevents autoload - // as well. - v = find_var(lp->ll_name, (flags & GLV_READ_ONLY) ? NULL : &ht, - flags & GLV_NO_AUTOLOAD); + // When we would write to the variable pass &ht and prevent autoload. + writing = !(flags & GLV_READ_ONLY); + v = find_var(lp->ll_name, writing ? &ht : NULL, + (flags & GLV_NO_AUTOLOAD) || writing); if (v == NULL && !quiet) semsg(_(e_undefined_variable_str), lp->ll_name); *p = cc; @@ -1972,13 +1975,15 @@ eval_func( int len = name_len; partial_T *partial; int ret = OK; + type_T *type = NULL; if (!evaluate) check_vars(s, len); // If "s" is the name of a variable of type VAR_FUNC // use its contents. - s = deref_func_name(s, &len, &partial, !evaluate); + s = deref_func_name(s, &len, &partial, + in_vim9script() ? &type : NULL, !evaluate); // Need to make a copy, in case evaluating the arguments makes // the name invalid. @@ -1996,6 +2001,7 @@ eval_func( funcexe.evaluate = evaluate; funcexe.partial = partial; funcexe.basetv = basetv; + funcexe.check_type = type; ret = get_func_tv(s, len, rettv, arg, evalarg, &funcexe); } vim_free(s);