patch 8.2.2288: Vim9: line break and comment not always skipped
Problem: Vim9: line break and comment not always skipped.
Solution: Skip over white space and then line break more consistently.
(closes #7610)
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index b7b9326..d22ece2 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -43,6 +43,11 @@
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,6 +2089,10 @@
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,7 +2674,7 @@
enddef
func Test_expr7_fails()
- call CheckDefFailure(["var x = (12"], "E110:", 1)
+ call CheckDefFailure(["var x = (12"], "E1097:", 3)
call CheckDefFailure(["var x = -'xx'"], "E1030:", 1)
call CheckDefFailure(["var x = +'xx'"], "E1030:", 1)
diff --git a/src/version.c b/src/version.c
index 87d3c3d..557d165 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2288,
+/**/
2287,
/**/
2286,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 2a2b44e..79d28c2 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2256,6 +2256,7 @@
}
/*
+ * 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,6 +2264,7 @@
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,14 +3020,13 @@
int count = 0;
dict_T *d = dict_alloc();
dictitem_T *item;
- char_u *whitep = *arg;
+ 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;
- *arg = skipwhite(*arg + 1);
for (;;)
{
char_u *key = NULL;
@@ -3112,7 +3113,6 @@
return FAIL;
}
- *arg = skipwhite(*arg + 1);
if (may_get_next_line(whitep, arg, cctx) == FAIL)
{
*arg = NULL;
@@ -3126,7 +3126,6 @@
++count;
whitep = *arg;
- *arg = skipwhite(*arg);
if (may_get_next_line(whitep, arg, cctx) == FAIL)
{
*arg = NULL;
@@ -3474,7 +3473,7 @@
static int
compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
{
- int ret;
+ int ret;
*arg = skipwhite(*arg + 1);
if (ppconst->pp_used <= PPSIZE - 10)
@@ -3488,7 +3487,8 @@
return FAIL;
ret = compile_expr0(arg, cctx);
}
- *arg = skipwhite(*arg);
+ if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
+ return FAIL;
if (**arg == ')')
++*arg;
else if (ret == OK)
@@ -3660,7 +3660,6 @@
ppconst->pp_is_const = FALSE;
++p;
- *arg = skipwhite(p);
if (may_get_next_line_error(p, arg, cctx) == FAIL)
return FAIL;
if (**arg == ':')
@@ -3678,7 +3677,7 @@
":", *arg);
return FAIL;
}
- if (may_get_next_line_error(p, arg, cctx) == FAIL)
+ if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
return FAIL;
*arg = skipwhite(*arg);
}
@@ -3692,8 +3691,7 @@
":", *arg);
return FAIL;
}
- *arg = skipwhite(*arg);
- if (may_get_next_line_error(p, arg, cctx) == 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,7 +3700,7 @@
{
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
- if (may_get_next_line_error(p, arg, cctx) == FAIL)
+ if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
return FAIL;
*arg = skipwhite(*arg);
}
@@ -4115,7 +4113,7 @@
return FAIL;
}
++*arg;
- if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL)
+ if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
return FAIL;
}
@@ -4174,7 +4172,6 @@
error_white_both(op, 1);
return FAIL;
}
- *arg = skipwhite(op + 1);
if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
return FAIL;
@@ -4251,7 +4248,6 @@
return FAIL;
}
- *arg = skipwhite(op + oplen);
if (may_get_next_line_error(op + oplen, arg, cctx) == FAIL)
return FAIL;
@@ -4381,7 +4377,6 @@
}
// get the second variable
- *arg = skipwhite(p + len);
if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
return FAIL;
@@ -4481,7 +4476,6 @@
? 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);
@@ -4674,7 +4668,6 @@
}
// 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)
@@ -4725,7 +4718,6 @@
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)
@@ -5414,7 +5406,6 @@
// 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)
@@ -5766,7 +5757,6 @@
--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)
@@ -6575,7 +6565,6 @@
// 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]))
@@ -6584,7 +6573,6 @@
return NULL;
}
wp = p + 2;
- p = skipwhite(wp);
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
return NULL;