patch 8.2.1155: Vim9: cannot handle line break inside lambda
Problem: Vim9: cannot handle line break inside lambda.
Solution: Pass the compilation context through. (closes #6407, closes #6409)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 07e0d27..c3c3808 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2397,8 +2397,8 @@
* comment. Skips over white space.
* Returns NULL if there is none.
*/
- static char_u *
-peek_next_line(cctx_T *cctx)
+ char_u *
+peek_next_line_from_context(cctx_T *cctx)
{
int lnum = cctx->ctx_lnum;
@@ -2430,7 +2430,7 @@
*nextp = NULL;
if (*p == NUL || (VIM_ISWHITE(*arg) && comment_start(p)))
{
- *nextp = peek_next_line(cctx);
+ *nextp = peek_next_line_from_context(cctx);
if (*nextp != NULL)
return *nextp;
}
@@ -2442,7 +2442,7 @@
* Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE.
* Returns NULL when at the end.
*/
- static char_u *
+ char_u *
next_line_from_context(cctx_T *cctx, int skip_comment)
{
char_u *line;
@@ -3079,9 +3079,14 @@
{
typval_T rettv;
ufunc_T *ufunc;
+ evalarg_T evalarg;
+
+ CLEAR_FIELD(evalarg);
+ evalarg.eval_flags = EVAL_EVALUATE;
+ evalarg.eval_cctx = cctx;
// Get the funcref in "rettv".
- if (get_lambda_tv(arg, &rettv, &EVALARG_EVALUATE) != OK)
+ if (get_lambda_tv(arg, &rettv, &evalarg) != OK)
return FAIL;
ufunc = rettv.vval.v_partial->pt_func;
@@ -3535,6 +3540,7 @@
/*
* Compile whatever comes after "name" or "name()".
+ * Advances "*arg" only when something was recognized.
*/
static int
compile_subscript(
@@ -3550,7 +3556,7 @@
if (*p == NUL || (VIM_ISWHITE(**arg) && comment_start(p)))
{
- char_u *next = peek_next_line(cctx);
+ char_u *next = peek_next_line_from_context(cctx);
// If a following line starts with "->{" or "->X" advance to that
// line, so that a line break before "->" is allowed.
@@ -3560,11 +3566,12 @@
next = next_line_from_context(cctx, TRUE);
if (next == NULL)
return FAIL;
- *arg = skipwhite(next);
+ *arg = next;
+ p = skipwhite(*arg);
}
}
- if (**arg == '(')
+ if (*p == '(')
{
garray_T *stack = &cctx->ctx_type_stack;
type_T *type;
@@ -3576,13 +3583,13 @@
// funcref(arg)
type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
- *arg = skipwhite(*arg + 1);
+ *arg = skipwhite(p + 1);
if (compile_arguments(arg, cctx, &argcount) == FAIL)
return FAIL;
if (generate_PCALL(cctx, argcount, end_leader, type, TRUE) == FAIL)
return FAIL;
}
- else if (**arg == '-' && (*arg)[1] == '>')
+ else if (*p == '-' && p[1] == '>')
{
if (generate_ppconst(cctx, ppconst) == FAIL)
return FAIL;
@@ -3594,7 +3601,7 @@
return FAIL;
*start_leader = end_leader; // don't apply again later
- p = *arg + 2;
+ p += 2;
*arg = skipwhite(p);
if (may_get_next_line(p, arg, cctx) == FAIL)
return FAIL;
@@ -3622,7 +3629,7 @@
return FAIL;
}
}
- else if (**arg == '[')
+ else if (*p == '[')
{
garray_T *stack = &cctx->ctx_type_stack;
type_T **typep;
@@ -3635,7 +3642,7 @@
if (generate_ppconst(cctx, ppconst) == FAIL)
return FAIL;
- p = *arg + 1;
+ ++p;
*arg = skipwhite(p);
if (may_get_next_line(p, arg, cctx) == FAIL)
return FAIL;
@@ -3671,12 +3678,12 @@
return FAIL;
}
}
- else if (**arg == '.' && (*arg)[1] != '.')
+ else if (*p == '.' && p[1] != '.')
{
if (generate_ppconst(cctx, ppconst) == FAIL)
return FAIL;
- ++*arg;
+ *arg = p + 1;
if (may_get_next_line(*arg, arg, cctx) == FAIL)
return FAIL;
// dictionary member: dict.name