Skip to content

Commit 5afd081

Browse files
committed
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)
1 parent cec77d4 commit 5afd081

3 files changed

Lines changed: 22 additions & 23 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def Test_expr1_trinary()
4343
name = 0
4444
assert_equal('two', name ? 'one' : 'two')
4545

46+
echo ['a'] + (1 ? ['b'] : ['c']
47+
)
48+
echo ['a'] + (1 ? ['b'] : ['c'] # comment
49+
)
50+
4651
# with constant condition expression is not evaluated
4752
assert_equal('one', 1 ? 'one' : xxx)
4853

@@ -2084,6 +2089,10 @@ def Test_expr7_dict()
20842089
var d = {a: () => 3, b: () => 7}
20852090
assert_equal(3, d.a())
20862091
assert_equal(7, d.b())
2092+
2093+
var cd = { # comment
2094+
key: 'val' # comment
2095+
}
20872096
END
20882097
CheckDefAndScriptSuccess(lines)
20892098

@@ -2665,7 +2674,7 @@ def Test_expr7_not()
26652674
enddef
26662675

26672676
func Test_expr7_fails()
2668-
call CheckDefFailure(["var x = (12"], "E110:", 1)
2677+
call CheckDefFailure(["var x = (12"], "E1097:", 3)
26692678

26702679
call CheckDefFailure(["var x = -'xx'"], "E1030:", 1)
26712680
call CheckDefFailure(["var x = +'xx'"], "E1030:", 1)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2288,
753755
/**/
754756
2287,
755757
/**/

src/vim9compile.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,13 +2256,15 @@ next_line_from_context(cctx_T *cctx, int skip_comment)
22562256
}
22572257

22582258
/*
2259+
* Skip over white space at "whitep" and assign to "*arg".
22592260
* If "*arg" is at the end of the line, advance to the next line.
22602261
* Also when "whitep" points to white space and "*arg" is on a "#".
22612262
* Return FAIL if beyond the last line, "*arg" is unmodified then.
22622263
*/
22632264
static int
22642265
may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
22652266
{
2267+
*arg = skipwhite(whitep);
22662268
if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg)))
22672269
{
22682270
char_u *next = next_line_from_context(cctx, TRUE);
@@ -3018,14 +3020,13 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
30183020
int count = 0;
30193021
dict_T *d = dict_alloc();
30203022
dictitem_T *item;
3021-
char_u *whitep = *arg;
3023+
char_u *whitep = *arg + 1;
30223024
char_u *p;
30233025
int is_const;
30243026
int is_all_const = TRUE; // reset when non-const encountered
30253027

30263028
if (d == NULL)
30273029
return FAIL;
3028-
*arg = skipwhite(*arg + 1);
30293030
for (;;)
30303031
{
30313032
char_u *key = NULL;
@@ -3112,7 +3113,6 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
31123113
return FAIL;
31133114
}
31143115

3115-
*arg = skipwhite(*arg + 1);
31163116
if (may_get_next_line(whitep, arg, cctx) == FAIL)
31173117
{
31183118
*arg = NULL;
@@ -3126,7 +3126,6 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
31263126
++count;
31273127

31283128
whitep = *arg;
3129-
*arg = skipwhite(*arg);
31303129
if (may_get_next_line(whitep, arg, cctx) == FAIL)
31313130
{
31323131
*arg = NULL;
@@ -3474,7 +3473,7 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
34743473
static int
34753474
compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
34763475
{
3477-
int ret;
3476+
int ret;
34783477

34793478
*arg = skipwhite(*arg + 1);
34803479
if (ppconst->pp_used <= PPSIZE - 10)
@@ -3488,7 +3487,8 @@ compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
34883487
return FAIL;
34893488
ret = compile_expr0(arg, cctx);
34903489
}
3491-
*arg = skipwhite(*arg);
3490+
if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
3491+
return FAIL;
34923492
if (**arg == ')')
34933493
++*arg;
34943494
else if (ret == OK)
@@ -3660,7 +3660,6 @@ compile_subscript(
36603660
ppconst->pp_is_const = FALSE;
36613661

36623662
++p;
3663-
*arg = skipwhite(p);
36643663
if (may_get_next_line_error(p, arg, cctx) == FAIL)
36653664
return FAIL;
36663665
if (**arg == ':')
@@ -3678,7 +3677,7 @@ compile_subscript(
36783677
":", *arg);
36793678
return FAIL;
36803679
}
3681-
if (may_get_next_line_error(p, arg, cctx) == FAIL)
3680+
if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
36823681
return FAIL;
36833682
*arg = skipwhite(*arg);
36843683
}
@@ -3692,8 +3691,7 @@ compile_subscript(
36923691
":", *arg);
36933692
return FAIL;
36943693
}
3695-
*arg = skipwhite(*arg);
3696-
if (may_get_next_line_error(p, arg, cctx) == FAIL)
3694+
if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
36973695
return FAIL;
36983696
if (**arg == ']')
36993697
// missing second index is equal to end of string
@@ -3702,7 +3700,7 @@ compile_subscript(
37023700
{
37033701
if (compile_expr0(arg, cctx) == FAIL)
37043702
return FAIL;
3705-
if (may_get_next_line_error(p, arg, cctx) == FAIL)
3703+
if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
37063704
return FAIL;
37073705
*arg = skipwhite(*arg);
37083706
}
@@ -4115,7 +4113,7 @@ compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
41154113
return FAIL;
41164114
}
41174115
++*arg;
4118-
if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL)
4116+
if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
41194117
return FAIL;
41204118
}
41214119

@@ -4174,7 +4172,6 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
41744172
error_white_both(op, 1);
41754173
return FAIL;
41764174
}
4177-
*arg = skipwhite(op + 1);
41784175
if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
41794176
return FAIL;
41804177

@@ -4251,7 +4248,6 @@ compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
42514248
return FAIL;
42524249
}
42534250

4254-
*arg = skipwhite(op + oplen);
42554251
if (may_get_next_line_error(op + oplen, arg, cctx) == FAIL)
42564252
return FAIL;
42574253

@@ -4381,7 +4377,6 @@ compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
43814377
}
43824378

43834379
// get the second variable
4384-
*arg = skipwhite(p + len);
43854380
if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
43864381
return FAIL;
43874382

@@ -4481,7 +4476,6 @@ compile_and_or(
44814476
? JUMP_IF_COND_TRUE : JUMP_IF_COND_FALSE, 0);
44824477

44834478
// eval the next expression
4484-
*arg = skipwhite(p + 2);
44854479
if (may_get_next_line_error(p + 2, arg, cctx) == FAIL)
44864480
{
44874481
ga_clear(&end_ga);
@@ -4674,7 +4668,6 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
46744668
}
46754669

46764670
// evaluate the second expression; any type is accepted
4677-
*arg = skipwhite(p + 1 + op_falsy);
46784671
if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL)
46794672
return FAIL;
46804673
if (compile_expr1(arg, cctx, ppconst) == FAIL)
@@ -4725,7 +4718,6 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
47254718
if (has_const_expr)
47264719
cctx->ctx_skip = save_skip == SKIP_YES || const_value
47274720
? SKIP_YES : SKIP_NOT;
4728-
*arg = skipwhite(p + 1);
47294721
if (may_get_next_line_error(p + 1, arg, cctx) == FAIL)
47304722
return FAIL;
47314723
if (compile_expr1(arg, cctx, ppconst) == FAIL)
@@ -5414,7 +5406,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
54145406
// A line break may follow the "=".
54155407

54165408
wp = op + oplen;
5417-
p = skipwhite(wp);
54185409
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
54195410
return FAIL;
54205411
if (compile_expr0(&p, cctx) == FAIL)
@@ -5766,7 +5757,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
57665757
--cctx->ctx_locals.ga_len;
57675758
instr_count = instr->ga_len;
57685759
wp = op + oplen;
5769-
p = skipwhite(wp);
57705760
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
57715761
{
57725762
if (new_local)
@@ -6575,7 +6565,6 @@ compile_for(char_u *arg_start, cctx_T *cctx)
65756565

65766566
// consume "in"
65776567
wp = p;
6578-
p = skipwhite(p);
65796568
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
65806569
return NULL;
65816570
if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
@@ -6584,7 +6573,6 @@ compile_for(char_u *arg_start, cctx_T *cctx)
65846573
return NULL;
65856574
}
65866575
wp = p + 2;
6587-
p = skipwhite(wp);
65886576
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
65896577
return NULL;
65906578

0 commit comments

Comments
 (0)