diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-04-28 20:00:40 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-04-28 20:00:40 +0200 |
commit | 03717bf6a27d753fe8f9d713d66594fb1940515f (patch) | |
tree | e0ef7149783492e0e684365d6c047f5adac5aee7 | |
parent | b80d2fb0e7b9adec4cff1bc4e2d30635cb70502e (diff) | |
download | vim-git-03717bf6a27d753fe8f9d713d66594fb1940515f.tar.gz |
patch 8.2.2816: Vim9: comment below expression in lambda causes problemsv8.2.2816
Problem: Vim9: comment below expression in lambda causes problems.
Solution: Use a single space for empty and comment lines. (closes #8156)
-rw-r--r-- | src/eval.c | 17 | ||||
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 7 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 23 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c index 97a00f759..f25454960 100644 --- a/src/eval.c +++ b/src/eval.c @@ -393,7 +393,7 @@ skip_expr(char_u **pp, evalarg_T *evalarg) } /* - * Skip over an expression at "*pp". + * Skip over an expression at "*arg". * If in Vim9 script and line breaks are encountered, the lines are * concatenated. "evalarg->eval_tofree" will be set accordingly. * "arg" is advanced to just after the expression. @@ -451,7 +451,7 @@ skip_expr_concatenate( // Line breaks encountered, concatenate all the lines. *((char_u **)gap->ga_data) = *start; - p = ga_concat_strings(gap, ""); + p = ga_concat_strings(gap, " "); // free the lines only when using getsourceline() if (evalarg->eval_cookie != NULL) @@ -2059,6 +2059,7 @@ eval_func( /* * Get the next line source line without advancing. But do skip over comment * lines. + * Only called for Vim9 script. */ static char_u * getline_peek_skip_comments(evalarg_T *evalarg) @@ -2116,6 +2117,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext) /* * To be called after eval_next_non_blank() sets "getnext" to TRUE. + * Only called for Vim9 script. */ char_u * eval_next_line(evalarg_T *evalarg) @@ -2131,7 +2133,16 @@ eval_next_line(evalarg_T *evalarg) ++evalarg->eval_break_count; if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK) { - // Going to concatenate the lines after parsing. + char_u *p = skipwhite(line); + + // Going to concatenate the lines after parsing. For an empty or + // comment line use an empty string. + if (*p == NUL || vim9_comment_start(p)) + { + vim_free(line); + line = vim_strsave((char_u *)""); + } + ((char_u **)gap->ga_data)[gap->ga_len] = line; ++gap->ga_len; } diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index fdedd5f04..de77b198b 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1887,6 +1887,7 @@ enddef def Test_expr7_lambda() var lines =<< trim END var La = () => 'result' + # comment assert_equal('result', La()) assert_equal([1, 3, 5], [1, 2, 3]->map((key, val) => key + val)) @@ -1897,6 +1898,12 @@ def Test_expr7_lambda() ) assert_equal([{}, {111: 111}, {}], dll) + # comment halfway an expression + var Ref = () => 4 + # comment + + 6 + assert_equal(10, Ref()) + ll = range(3) map(ll, (k, v) => v == 8 || v == 9 diff --git a/src/version.c b/src/version.c index a399369b5..b1d5be795 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2816, +/**/ 2815, /**/ 2814, |