summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-08-19 21:08:30 +0200
committerBram Moolenaar <Bram@vim.org>2021-08-19 21:08:30 +0200
commitc66f645b809d0852592ca37afacb9031b5950c7f (patch)
treefe897dff075ffe17343309646fb09973af091207
parentdea561111a5761bf99397a246b8baa43e73288de (diff)
downloadvim-git-c66f645b809d0852592ca37afacb9031b5950c7f.tar.gz
patch 8.2.3359: Vim9: error for type when variable is not setv8.2.3359
Problem: Vim9: error for type when variable is not set. Solution: Give a specific error for a NULL function. (closes #8773)
-rw-r--r--src/errors.h2
-rw-r--r--src/testdir/test_vim9_func.vim9
-rw-r--r--src/version.c2
-rw-r--r--src/vim9type.c10
4 files changed, 23 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index 3468ab780..b4c111d3f 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -652,3 +652,5 @@ EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
INIT(= N_("E1233: exists_compiled() can only be used in a :def function"));
EXTERN char e_legacy_must_be_followed_by_command[]
INIT(= N_("E1234: legacy must be followed by a command"));
+EXTERN char e_function_reference_is_not_set[]
+ INIT(= N_("E1235: Function reference is not set"));
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 0ffe68632..f0c4c0d91 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -2696,6 +2696,15 @@ def Test_partial_call()
assert_equal('ooooo', RepeatFunc(5))
END
CheckDefAndScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ def Foo(Parser: any)
+ enddef
+ var Expr: func(dict<any>): dict<any>
+ const Call = Foo(Expr)
+ END
+ CheckScriptFailure(lines, 'E1235:')
enddef
def Test_cmd_modifier()
diff --git a/src/version.c b/src/version.c
index 74b234aa8..b47b1e358 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3359,
+/**/
3358,
/**/
3357,
diff --git a/src/vim9type.c b/src/vim9type.c
index ca090cbe5..d6e01cd7a 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -461,6 +461,16 @@ check_typval_type(type_T *expected, typval_T *actual_tv, where_T where)
type_T *actual_type;
int res = FAIL;
+ // For some values there is no type, assume an error will be given later
+ // for an invalid value.
+ if ((actual_tv->v_type == VAR_FUNC && actual_tv->vval.v_string == NULL)
+ || (actual_tv->v_type == VAR_PARTIAL
+ && actual_tv->vval.v_partial == NULL))
+ {
+ emsg(_(e_function_reference_is_not_set));
+ return FAIL;
+ }
+
ga_init2(&type_list, sizeof(type_T *), 10);
actual_type = typval2type(actual_tv, get_copyID(), &type_list, TRUE);
if (actual_type != NULL)