Mercurial > vim
comparison src/eval.c @ 24553:cb0d344bd381 v8.2.2816
patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Commit: https://github.com/vim/vim/commit/03717bf6a27d753fe8f9d713d66594fb1940515f
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Apr 28 20:00:40 2021 +0200
patch 8.2.2816: Vim9: comment below expression in lambda causes problems
Problem: Vim9: comment below expression in lambda causes problems.
Solution: Use a single space for empty and comment lines. (closes https://github.com/vim/vim/issues/8156)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 28 Apr 2021 20:15:04 +0200 |
parents | 9c404d78d767 |
children | a4fda40e0bb9 |
comparison
equal
deleted
inserted
replaced
24552:b243f528702a | 24553:cb0d344bd381 |
---|---|
391 *pp = skipwhite(*pp); | 391 *pp = skipwhite(*pp); |
392 return eval1(pp, &rettv, evalarg); | 392 return eval1(pp, &rettv, evalarg); |
393 } | 393 } |
394 | 394 |
395 /* | 395 /* |
396 * Skip over an expression at "*pp". | 396 * Skip over an expression at "*arg". |
397 * If in Vim9 script and line breaks are encountered, the lines are | 397 * If in Vim9 script and line breaks are encountered, the lines are |
398 * concatenated. "evalarg->eval_tofree" will be set accordingly. | 398 * concatenated. "evalarg->eval_tofree" will be set accordingly. |
399 * "arg" is advanced to just after the expression. | 399 * "arg" is advanced to just after the expression. |
400 * "start" is set to the start of the expression, "end" to just after the end. | 400 * "start" is set to the start of the expression, "end" to just after the end. |
401 * Also when the expression is copied to allocated memory. | 401 * Also when the expression is copied to allocated memory. |
449 char_u *p; | 449 char_u *p; |
450 size_t endoff = STRLEN(*arg); | 450 size_t endoff = STRLEN(*arg); |
451 | 451 |
452 // Line breaks encountered, concatenate all the lines. | 452 // Line breaks encountered, concatenate all the lines. |
453 *((char_u **)gap->ga_data) = *start; | 453 *((char_u **)gap->ga_data) = *start; |
454 p = ga_concat_strings(gap, ""); | 454 p = ga_concat_strings(gap, " "); |
455 | 455 |
456 // free the lines only when using getsourceline() | 456 // free the lines only when using getsourceline() |
457 if (evalarg->eval_cookie != NULL) | 457 if (evalarg->eval_cookie != NULL) |
458 { | 458 { |
459 // Do not free the first line, the caller can still use it. | 459 // Do not free the first line, the caller can still use it. |
2057 } | 2057 } |
2058 | 2058 |
2059 /* | 2059 /* |
2060 * Get the next line source line without advancing. But do skip over comment | 2060 * Get the next line source line without advancing. But do skip over comment |
2061 * lines. | 2061 * lines. |
2062 * Only called for Vim9 script. | |
2062 */ | 2063 */ |
2063 static char_u * | 2064 static char_u * |
2064 getline_peek_skip_comments(evalarg_T *evalarg) | 2065 getline_peek_skip_comments(evalarg_T *evalarg) |
2065 { | 2066 { |
2066 for (;;) | 2067 for (;;) |
2114 return p; | 2115 return p; |
2115 } | 2116 } |
2116 | 2117 |
2117 /* | 2118 /* |
2118 * To be called after eval_next_non_blank() sets "getnext" to TRUE. | 2119 * To be called after eval_next_non_blank() sets "getnext" to TRUE. |
2120 * Only called for Vim9 script. | |
2119 */ | 2121 */ |
2120 char_u * | 2122 char_u * |
2121 eval_next_line(evalarg_T *evalarg) | 2123 eval_next_line(evalarg_T *evalarg) |
2122 { | 2124 { |
2123 garray_T *gap = &evalarg->eval_ga; | 2125 garray_T *gap = &evalarg->eval_ga; |
2129 else | 2131 else |
2130 line = next_line_from_context(evalarg->eval_cctx, TRUE); | 2132 line = next_line_from_context(evalarg->eval_cctx, TRUE); |
2131 ++evalarg->eval_break_count; | 2133 ++evalarg->eval_break_count; |
2132 if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK) | 2134 if (gap->ga_itemsize > 0 && ga_grow(gap, 1) == OK) |
2133 { | 2135 { |
2134 // Going to concatenate the lines after parsing. | 2136 char_u *p = skipwhite(line); |
2137 | |
2138 // Going to concatenate the lines after parsing. For an empty or | |
2139 // comment line use an empty string. | |
2140 if (*p == NUL || vim9_comment_start(p)) | |
2141 { | |
2142 vim_free(line); | |
2143 line = vim_strsave((char_u *)""); | |
2144 } | |
2145 | |
2135 ((char_u **)gap->ga_data)[gap->ga_len] = line; | 2146 ((char_u **)gap->ga_data)[gap->ga_len] = line; |
2136 ++gap->ga_len; | 2147 ++gap->ga_len; |
2137 } | 2148 } |
2138 else if (evalarg->eval_cookie != NULL) | 2149 else if (evalarg->eval_cookie != NULL) |
2139 { | 2150 { |