patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Problem: Vim9: cannot call a function declared later in Vim9 script.
Solution: Make two passes through the script file.
diff --git a/src/userfunc.c b/src/userfunc.c
index 1d5f5d5..b33aee7 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2378,7 +2378,7 @@
* Returns a pointer to the function or NULL if no function defined.
*/
ufunc_T *
-def_function(exarg_T *eap, char_u *name_arg, void *context)
+def_function(exarg_T *eap, char_u *name_arg, void *context, int compile)
{
char_u *theline;
char_u *line_to_free = NULL;
@@ -3241,6 +3241,7 @@
p = ret_type;
fp->uf_ret_type = parse_type(&p, &fp->uf_type_list);
}
+ SOURCING_LNUM = lnum_save;
}
fp->uf_lines = newlines;
@@ -3273,8 +3274,8 @@
is_export = FALSE;
}
- // ":def Func()" needs to be compiled
- if (eap->cmdidx == CMD_def)
+ // ":def Func()" may need to be compiled
+ if (eap->cmdidx == CMD_def && compile)
compile_def_function(fp, FALSE, context);
goto ret_free;
@@ -3304,7 +3305,7 @@
void
ex_function(exarg_T *eap)
{
- def_function(eap, NULL, NULL);
+ (void)def_function(eap, NULL, NULL, TRUE);
}
/*