Mercurial > vim
diff src/vim9compile.c @ 21208:09377fd59b2e v8.2.1155
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Commit: https://github.com/vim/vim/commit/7a4b8980ea5ecaea061caae7816ea62cc4940011
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 8 17:36:21 2020 +0200
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 https://github.com/vim/vim/issues/6407, closes https://github.com/vim/vim/issues/6409)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 08 Jul 2020 17:45:06 +0200 |
parents | 1a4e22aa2eb3 |
children | 44611891e22c |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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 *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 * 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 *cct { 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 *sta /* * 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