Skip to content

Commit c66f645

Browse files
committed
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)
1 parent dea5611 commit c66f645

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,3 +652,5 @@ EXTERN char e_exists_compiled_can_only_be_used_in_def_function[]
652652
INIT(= N_("E1233: exists_compiled() can only be used in a :def function"));
653653
EXTERN char e_legacy_must_be_followed_by_command[]
654654
INIT(= N_("E1234: legacy must be followed by a command"));
655+
EXTERN char e_function_reference_is_not_set[]
656+
INIT(= N_("E1235: Function reference is not set"));

src/testdir/test_vim9_func.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,15 @@ def Test_partial_call()
26962696
assert_equal('ooooo', RepeatFunc(5))
26972697
END
26982698
CheckDefAndScriptSuccess(lines)
2699+
2700+
lines =<< trim END
2701+
vim9script
2702+
def Foo(Parser: any)
2703+
enddef
2704+
var Expr: func(dict<any>): dict<any>
2705+
const Call = Foo(Expr)
2706+
END
2707+
CheckScriptFailure(lines, 'E1235:')
26992708
enddef
27002709

27012710
def Test_cmd_modifier()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3359,
758760
/**/
759761
3358,
760762
/**/

src/vim9type.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,16 @@ check_typval_type(type_T *expected, typval_T *actual_tv, where_T where)
461461
type_T *actual_type;
462462
int res = FAIL;
463463

464+
// For some values there is no type, assume an error will be given later
465+
// for an invalid value.
466+
if ((actual_tv->v_type == VAR_FUNC && actual_tv->vval.v_string == NULL)
467+
|| (actual_tv->v_type == VAR_PARTIAL
468+
&& actual_tv->vval.v_partial == NULL))
469+
{
470+
emsg(_(e_function_reference_is_not_set));
471+
return FAIL;
472+
}
473+
464474
ga_init2(&type_list, sizeof(type_T *), 10);
465475
actual_type = typval2type(actual_tv, get_copyID(), &type_list, TRUE);
466476
if (actual_type != NULL)

0 commit comments

Comments
 (0)