From c66f645b809d0852592ca37afacb9031b5950c7f Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Thu, 19 Aug 2021 21:08:30 +0200
Subject: [PATCH] patch 8.2.3359: Vim9: error for type when variable is not set

Problem:    Vim9: error for type when variable is not set.
Solution:   Give a specific error for a NULL function. (closes #8773)
---
 src/errors.h                   |  2 ++
 src/testdir/test_vim9_func.vim |  9 +++++++++
 src/version.c                  |  2 ++
 src/vim9type.c                 | 10 ++++++++++
 4 files changed, 23 insertions(+)

diff --git a/src/errors.h b/src/errors.h
index 3468ab780c..b4c111d3f1 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 0ffe68632f..f0c4c0d91c 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 74b234aa8c..b47b1e3581 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3359,
 /**/
     3358,
 /**/
diff --git a/src/vim9type.c b/src/vim9type.c
index ca090cbe59..d6e01cd7a6 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)
-- 
GitLab