patch 8.1.1310: named function arguments are never optional
Problem: Named function arguments are never optional.
Solution: Support optional function arguments with a default value. (Andy
Massimino, closes #3952)
diff --git a/src/structs.h b/src/structs.h
index ca678f8..16e5ce3 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -1402,42 +1402,43 @@
*/
typedef struct
{
- int uf_varargs; /* variable nr of arguments */
+ int uf_varargs; // variable nr of arguments
int uf_flags;
- int uf_calls; /* nr of active calls */
- int uf_cleared; /* func_clear() was already called */
- garray_T uf_args; /* arguments */
- garray_T uf_lines; /* function lines */
+ int uf_calls; // nr of active calls
+ int uf_cleared; // func_clear() was already called
+ garray_T uf_args; // arguments
+ garray_T uf_def_args; // default argument expressions
+ garray_T uf_lines; // function lines
# ifdef FEAT_PROFILE
- int uf_profiling; /* TRUE when func is being profiled */
+ int uf_profiling; // TRUE when func is being profiled
int uf_prof_initialized;
- /* profiling the function as a whole */
- int uf_tm_count; /* nr of calls */
- proftime_T uf_tm_total; /* time spent in function + children */
- proftime_T uf_tm_self; /* time spent in function itself */
- proftime_T uf_tm_children; /* time spent in children this call */
- /* profiling the function per line */
- int *uf_tml_count; /* nr of times line was executed */
- proftime_T *uf_tml_total; /* time spent in a line + children */
- proftime_T *uf_tml_self; /* time spent in a line itself */
- proftime_T uf_tml_start; /* start time for current line */
- proftime_T uf_tml_children; /* time spent in children for this line */
- proftime_T uf_tml_wait; /* start wait time for current line */
- int uf_tml_idx; /* index of line being timed; -1 if none */
- int uf_tml_execed; /* line being timed was executed */
+ // profiling the function as a whole
+ int uf_tm_count; // nr of calls
+ proftime_T uf_tm_total; // time spent in function + children
+ proftime_T uf_tm_self; // time spent in function itself
+ proftime_T uf_tm_children; // time spent in children this call
+ // profiling the function per line
+ int *uf_tml_count; // nr of times line was executed
+ proftime_T *uf_tml_total; // time spent in a line + children
+ proftime_T *uf_tml_self; // time spent in a line itself
+ proftime_T uf_tml_start; // start time for current line
+ proftime_T uf_tml_children; // time spent in children for this line
+ proftime_T uf_tml_wait; // start wait time for current line
+ int uf_tml_idx; // index of line being timed; -1 if none
+ int uf_tml_execed; // line being timed was executed
# endif
- sctx_T uf_script_ctx; /* SCTX where function was defined,
- used for s: variables */
- int uf_refcount; /* reference count, see func_name_refcount() */
- funccall_T *uf_scoped; /* l: local variables for closure */
- char_u uf_name[1]; /* name of function (actually longer); can
- start with <SNR>123_ (<SNR> is K_SPECIAL
- KS_EXTRA KE_SNR) */
+ sctx_T uf_script_ctx; // SCTX where function was defined,
+ // used for s: variables
+ int uf_refcount; // reference count, see func_name_refcount()
+ funccall_T *uf_scoped; // l: local variables for closure
+ char_u uf_name[1]; // name of function (actually longer); can
+ // start with <SNR>123_ (<SNR> is K_SPECIAL
+ // KS_EXTRA KE_SNR)
} ufunc_T;
-#define MAX_FUNC_ARGS 20 /* maximum number of function arguments */
-#define VAR_SHORT_LEN 20 /* short variable name length */
-#define FIXVAR_CNT 12 /* number of fixed variables */
+#define MAX_FUNC_ARGS 20 // maximum number of function arguments
+#define VAR_SHORT_LEN 20 // short variable name length
+#define FIXVAR_CNT 12 // number of fixed variables
/* structure to hold info for a function that is currently being executed. */
struct funccall_S