changeset 25646:99fbffe75217 v8.2.3359

patch 8.2.3359: Vim9: error for type when variable is not set Commit: https://github.com/vim/vim/commit/c66f645b809d0852592ca37afacb9031b5950c7f Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 19 21:08:30 2021 +0200 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 https://github.com/vim/vim/issues/8773)
author Bram Moolenaar <Bram@vim.org>
date Thu, 19 Aug 2021 21:15:04 +0200
parents ce10490c6b2c
children b6be34f354e6
files src/errors.h src/testdir/test_vim9_func.vim src/version.c src/vim9type.c
diffstat 4 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -652,3 +652,5 @@ EXTERN char e_exists_compiled_can_only_b
 	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"));
--- 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()
--- 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,
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -461,6 +461,16 @@ check_typval_type(type_T *expected, typv
     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)