patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Problem: Vim9: cannot split an expression into multiple lines.
Solution: Continue in next line after an operator.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 201b7b0..7e7ecb8 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2070,6 +2070,24 @@
}
/*
+ * If "*arg" is at the end of the line, advance to the next line.
+ * Return FAIL if beyond the last line, "*arg" is unmodified then.
+ */
+ static int
+may_get_next_line(char_u **arg, cctx_T *cctx)
+{
+ if (**arg == NUL)
+ {
+ char_u *next = next_line_from_context(cctx);
+
+ if (next == NULL)
+ return FAIL;
+ *arg = skipwhite(next);
+ }
+ return OK;
+}
+
+/*
* Generate an instruction to load script-local variable "name", without the
* leading "s:".
* Also finds imported variables.
@@ -3394,14 +3412,17 @@
op = skipwhite(*arg);
if (*op != '*' && *op != '/' && *op != '%')
break;
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(op[1]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1]))
{
char_u buf[3];
vim_strncpy(buf, op, 1);
semsg(_(e_white_both), buf);
+ return FAIL;
}
*arg = skipwhite(op + 1);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
// get the second variable
if (compile_expr7(arg, cctx) == FAIL)
@@ -3438,15 +3459,18 @@
break;
oplen = (*op == '.' ? 2 : 1);
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(op[oplen]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen]))
{
char_u buf[3];
vim_strncpy(buf, op, oplen);
semsg(_(e_white_both), buf);
+ return FAIL;
}
*arg = skipwhite(op + oplen);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
// get the second variable
if (compile_expr6(arg, cctx) == FAIL)
@@ -3572,16 +3596,20 @@
++len;
// nothing appended: match case
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[len]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len]))
{
char_u buf[7];
vim_strncpy(buf, p, len);
semsg(_(e_white_both), buf);
+ return FAIL;
}
// get the second variable
*arg = skipwhite(p + len);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
+
if (compile_expr5(arg, cctx) == FAIL)
return FAIL;
@@ -3611,8 +3639,11 @@
ga_init2(&end_ga, sizeof(int), 10);
while (p[0] == opchar && p[1] == opchar)
{
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[2]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2]))
+ {
semsg(_(e_white_both), op);
+ return FAIL;
+ }
if (ga_grow(&end_ga, 1) == FAIL)
{
@@ -3626,6 +3657,9 @@
// eval the next expression
*arg = skipwhite(p + 2);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
+
if ((opchar == '|' ? compile_expr3(arg, cctx)
: compile_expr4(arg, cctx)) == FAIL)
{
@@ -3726,13 +3760,19 @@
type_T *type1;
type_T *type2;
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[1]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1]))
+ {
semsg(_(e_white_both), "?");
+ return FAIL;
+ }
generate_JUMP(cctx, JUMP_IF_FALSE, 0);
// evaluate the second expression; any type is accepted
*arg = skipwhite(p + 1);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
+
if (compile_expr1(arg, cctx) == FAIL)
return FAIL;
@@ -3754,11 +3794,17 @@
emsg(_(e_missing_colon));
return FAIL;
}
- if (!VIM_ISWHITE(**arg) || !VIM_ISWHITE(p[1]))
+ if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1]))
+ {
semsg(_(e_white_both), ":");
+ return FAIL;
+ }
// evaluate the third expression
*arg = skipwhite(p + 1);
+ if (may_get_next_line(arg, cctx) == FAIL)
+ return FAIL;
+
if (compile_expr1(arg, cctx) == FAIL)
return FAIL;