To: vim_dev@googlegroups.com Subject: Patch 8.2.2288 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2288 Problem: Vim9: line break and comment not always skipped. Solution: Skip over white space and then line break more consistently. (closes #7610) Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.2287/src/vim9compile.c 2021-01-02 19:44:50.702794031 +0100 --- src/vim9compile.c 2021-01-03 18:29:47.360855537 +0100 *************** *** 2256,2261 **** --- 2256,2262 ---- } /* + * Skip over white space at "whitep" and assign to "*arg". * If "*arg" is at the end of the line, advance to the next line. * Also when "whitep" points to white space and "*arg" is on a "#". * Return FAIL if beyond the last line, "*arg" is unmodified then. *************** *** 2263,2268 **** --- 2264,2270 ---- static int may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx) { + *arg = skipwhite(whitep); if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg))) { char_u *next = next_line_from_context(cctx, TRUE); *************** *** 3018,3031 **** int count = 0; dict_T *d = dict_alloc(); dictitem_T *item; ! char_u *whitep = *arg; char_u *p; int is_const; int is_all_const = TRUE; // reset when non-const encountered if (d == NULL) return FAIL; - *arg = skipwhite(*arg + 1); for (;;) { char_u *key = NULL; --- 3020,3032 ---- int count = 0; dict_T *d = dict_alloc(); dictitem_T *item; ! char_u *whitep = *arg + 1; char_u *p; int is_const; int is_all_const = TRUE; // reset when non-const encountered if (d == NULL) return FAIL; for (;;) { char_u *key = NULL; *************** *** 3112,3118 **** return FAIL; } - *arg = skipwhite(*arg + 1); if (may_get_next_line(whitep, arg, cctx) == FAIL) { *arg = NULL; --- 3113,3118 ---- *************** *** 3126,3132 **** ++count; whitep = *arg; - *arg = skipwhite(*arg); if (may_get_next_line(whitep, arg, cctx) == FAIL) { *arg = NULL; --- 3126,3131 ---- *************** *** 3474,3480 **** static int compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) { ! int ret; *arg = skipwhite(*arg + 1); if (ppconst->pp_used <= PPSIZE - 10) --- 3473,3479 ---- static int compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) { ! int ret; *arg = skipwhite(*arg + 1); if (ppconst->pp_used <= PPSIZE - 10) *************** *** 3488,3494 **** return FAIL; ret = compile_expr0(arg, cctx); } ! *arg = skipwhite(*arg); if (**arg == ')') ++*arg; else if (ret == OK) --- 3487,3494 ---- return FAIL; ret = compile_expr0(arg, cctx); } ! if (may_get_next_line_error(*arg, arg, cctx) == FAIL) ! return FAIL; if (**arg == ')') ++*arg; else if (ret == OK) *************** *** 3660,3666 **** ppconst->pp_is_const = FALSE; ++p; - *arg = skipwhite(p); if (may_get_next_line_error(p, arg, cctx) == FAIL) return FAIL; if (**arg == ':') --- 3660,3665 ---- *************** *** 3678,3684 **** ":", *arg); return FAIL; } ! if (may_get_next_line_error(p, arg, cctx) == FAIL) return FAIL; *arg = skipwhite(*arg); } --- 3677,3683 ---- ":", *arg); return FAIL; } ! if (may_get_next_line_error(*arg, arg, cctx) == FAIL) return FAIL; *arg = skipwhite(*arg); } *************** *** 3692,3699 **** ":", *arg); return FAIL; } ! *arg = skipwhite(*arg); ! if (may_get_next_line_error(p, arg, cctx) == FAIL) return FAIL; if (**arg == ']') // missing second index is equal to end of string --- 3691,3697 ---- ":", *arg); return FAIL; } ! if (may_get_next_line_error(*arg, arg, cctx) == FAIL) return FAIL; if (**arg == ']') // missing second index is equal to end of string *************** *** 3702,3708 **** { if (compile_expr0(arg, cctx) == FAIL) return FAIL; ! if (may_get_next_line_error(p, arg, cctx) == FAIL) return FAIL; *arg = skipwhite(*arg); } --- 3700,3706 ---- { if (compile_expr0(arg, cctx) == FAIL) return FAIL; ! if (may_get_next_line_error(*arg, arg, cctx) == FAIL) return FAIL; *arg = skipwhite(*arg); } *************** *** 4115,4121 **** return FAIL; } ++*arg; ! if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL) return FAIL; } --- 4113,4119 ---- return FAIL; } ++*arg; ! if (may_get_next_line_error(*arg, arg, cctx) == FAIL) return FAIL; } *************** *** 4174,4180 **** error_white_both(op, 1); return FAIL; } - *arg = skipwhite(op + 1); if (may_get_next_line_error(op + 1, arg, cctx) == FAIL) return FAIL; --- 4172,4177 ---- *************** *** 4251,4257 **** return FAIL; } - *arg = skipwhite(op + oplen); if (may_get_next_line_error(op + oplen, arg, cctx) == FAIL) return FAIL; --- 4248,4253 ---- *************** *** 4381,4387 **** } // get the second variable - *arg = skipwhite(p + len); if (may_get_next_line_error(p + len, arg, cctx) == FAIL) return FAIL; --- 4377,4382 ---- *************** *** 4481,4487 **** ? JUMP_IF_COND_TRUE : JUMP_IF_COND_FALSE, 0); // eval the next expression - *arg = skipwhite(p + 2); if (may_get_next_line_error(p + 2, arg, cctx) == FAIL) { ga_clear(&end_ga); --- 4476,4481 ---- *************** *** 4674,4680 **** } // evaluate the second expression; any type is accepted - *arg = skipwhite(p + 1 + op_falsy); if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL) return FAIL; if (compile_expr1(arg, cctx, ppconst) == FAIL) --- 4668,4673 ---- *************** *** 4725,4731 **** if (has_const_expr) cctx->ctx_skip = save_skip == SKIP_YES || const_value ? SKIP_YES : SKIP_NOT; - *arg = skipwhite(p + 1); if (may_get_next_line_error(p + 1, arg, cctx) == FAIL) return FAIL; if (compile_expr1(arg, cctx, ppconst) == FAIL) --- 4718,4723 ---- *************** *** 5414,5420 **** // A line break may follow the "=". wp = op + oplen; - p = skipwhite(wp); if (may_get_next_line_error(wp, &p, cctx) == FAIL) return FAIL; if (compile_expr0(&p, cctx) == FAIL) --- 5406,5411 ---- *************** *** 5766,5772 **** --cctx->ctx_locals.ga_len; instr_count = instr->ga_len; wp = op + oplen; - p = skipwhite(wp); if (may_get_next_line_error(wp, &p, cctx) == FAIL) { if (new_local) --- 5757,5762 ---- *************** *** 6575,6581 **** // consume "in" wp = p; - p = skipwhite(p); if (may_get_next_line_error(wp, &p, cctx) == FAIL) return NULL; if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2])) --- 6565,6570 ---- *************** *** 6584,6590 **** return NULL; } wp = p + 2; - p = skipwhite(wp); if (may_get_next_line_error(wp, &p, cctx) == FAIL) return NULL; --- 6573,6578 ---- *** ../vim-8.2.2287/src/testdir/test_vim9_expr.vim 2021-01-01 19:17:52.297976777 +0100 --- src/testdir/test_vim9_expr.vim 2021-01-03 18:30:45.484727103 +0100 *************** *** 43,48 **** --- 43,53 ---- name = 0 assert_equal('two', name ? 'one' : 'two') + echo ['a'] + (1 ? ['b'] : ['c'] + ) + echo ['a'] + (1 ? ['b'] : ['c'] # comment + ) + # with constant condition expression is not evaluated assert_equal('one', 1 ? 'one' : xxx) *************** *** 2084,2089 **** --- 2089,2098 ---- var d = {a: () => 3, b: () => 7} assert_equal(3, d.a()) assert_equal(7, d.b()) + + var cd = { # comment + key: 'val' # comment + } END CheckDefAndScriptSuccess(lines) *************** *** 2665,2671 **** enddef func Test_expr7_fails() ! call CheckDefFailure(["var x = (12"], "E110:", 1) call CheckDefFailure(["var x = -'xx'"], "E1030:", 1) call CheckDefFailure(["var x = +'xx'"], "E1030:", 1) --- 2674,2680 ---- enddef func Test_expr7_fails() ! call CheckDefFailure(["var x = (12"], "E1097:", 3) call CheckDefFailure(["var x = -'xx'"], "E1030:", 1) call CheckDefFailure(["var x = +'xx'"], "E1030:", 1) *** ../vim-8.2.2287/src/version.c 2021-01-03 17:39:24.438674804 +0100 --- src/version.c 2021-01-03 18:17:03.615260147 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2288, /**/ -- From "know your smileys": :-X My lips are sealed /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///