0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2020-07-08 17:36:21 +02:00
parent c620c055ce
commit 7a4b8980ea
6 changed files with 114 additions and 62 deletions

View File

@@ -2397,8 +2397,8 @@ comment_start(char_u *p)
* 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 @@ may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp)
*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 @@ may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp)
* 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 @@ compile_lambda(char_u **arg, cctx_T *cctx)
{
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_leader(cctx_T *cctx, char_u *start, char_u *end)
/*
* Compile whatever comes after "name" or "name()".
* Advances "*arg" only when something was recognized.
*/
static int
compile_subscript(
@@ -3550,7 +3556,7 @@ compile_subscript(
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 @@ compile_subscript(
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 @@ compile_subscript(
// 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 @@ compile_subscript(
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 @@ compile_subscript(
return FAIL;
}
}
else if (**arg == '[')
else if (*p == '[')
{
garray_T *stack = &cctx->ctx_type_stack;
type_T **typep;
@@ -3635,7 +3642,7 @@ compile_subscript(
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 @@ compile_subscript(
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