# HG changeset patch # User Bram Moolenaar # Date 1629400504 -7200 # Node ID 99fbffe75217009c61bf6c907269b88770aa1b76 # Parent ce10490c6b2cf4ce8c4537b8f80bfe7c18e86fff patch 8.2.3359: Vim9: error for type when variable is not set Commit: https://github.com/vim/vim/commit/c66f645b809d0852592ca37afacb9031b5950c7f Author: Bram Moolenaar 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) diff --git a/src/errors.h b/src/errors.h --- 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")); diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- 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): dict + const Call = Foo(Expr) + END + CheckScriptFailure(lines, 'E1235:') enddef def Test_cmd_modifier() diff --git a/src/version.c b/src/version.c --- 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 --- 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)