Skip to content

Commit 7cebe8b

Browse files
committed
patch 8.2.2396: Vim9: no white space allowed before "->"
Problem: Vim9: no white space allowed before "->". Solution: Allow for white space. (closes #7725)
1 parent 9a562c1 commit 7cebe8b

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/eval.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,7 @@ call_func_rettv(
36713671

36723672
/*
36733673
* Evaluate "->method()".
3674-
* "*arg" points to the '-'.
3674+
* "*arg" points to "method".
36753675
* Returns FAIL or OK. "*arg" is advanced to after the ')'.
36763676
*/
36773677
static int
@@ -3686,8 +3686,6 @@ eval_lambda(
36863686
typval_T base = *rettv;
36873687
int ret;
36883688

3689-
// Skip over the ->.
3690-
*arg += 2;
36913689
rettv->v_type = VAR_UNKNOWN;
36923690

36933691
if (**arg == '{')
@@ -3735,7 +3733,7 @@ eval_lambda(
37353733

37363734
/*
37373735
* Evaluate "->method()".
3738-
* "*arg" points to the '-'.
3736+
* "*arg" points to "method".
37393737
* Returns FAIL or OK. "*arg" is advanced to after the ')'.
37403738
*/
37413739
static int
@@ -3753,8 +3751,6 @@ eval_method(
37533751
int evaluate = evalarg != NULL
37543752
&& (evalarg->eval_flags & EVAL_EVALUATE);
37553753

3756-
// Skip over the ->.
3757-
*arg += 2;
37583754
rettv->v_type = VAR_UNKNOWN;
37593755

37603756
name = *arg;
@@ -5765,10 +5761,10 @@ handle_subscript(
57655761
}
57665762
else if (p[0] == '-' && p[1] == '>')
57675763
{
5768-
*arg = p;
5764+
*arg = skipwhite(p + 2);
57695765
if (ret == OK)
57705766
{
5771-
if (((*arg)[2] == '{' && !in_vim9script()) || (*arg)[2] == '(')
5767+
if ((**arg == '{' && !in_vim9script()) || **arg == '(')
57725768
// expr->{lambda}() or expr->(lambda)()
57735769
ret = eval_lambda(arg, rettv, evalarg, verbose);
57745770
else

src/ex_docmd.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,8 +3313,9 @@ find_ex_command(
33133313
if (vim_strchr((char_u *)"{('[\"@", *p) != NULL
33143314
|| ((p = to_name_const_end(pskip)) > eap->cmd && *p != NUL))
33153315
{
3316-
int oplen;
3317-
int heredoc;
3316+
int oplen;
3317+
int heredoc;
3318+
char_u *swp = skipwhite(p);
33183319

33193320
if (
33203321
// "(..." is an expression.
@@ -3332,7 +3333,7 @@ find_ex_command(
33323333
|| eap->cmd[1] == ':'
33333334
)
33343335
// "varname->func()" is an expression.
3335-
: (*p == '-' && p[1] == '>')))
3336+
: (*swp == '-' && swp[1] == '>')))
33363337
{
33373338
if (*eap->cmd == '{' && ends_excmd(*skipwhite(eap->cmd + 1)))
33383339
{

src/testdir/test_vim9_cmd.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ def Test_method_call_linebreak()
319319
CheckScriptSuccess(lines)
320320
enddef
321321

322+
def Test_method_call_whitespace()
323+
var lines =<< trim END
324+
new
325+
var yank = 'text'
326+
yank->setline(1)
327+
yank ->setline(2)
328+
yank-> setline(3)
329+
yank -> setline(4)
330+
assert_equal(['text', 'text', 'text', 'text'], getline(1, 4))
331+
bwipe!
332+
END
333+
CheckDefAndScriptSuccess(lines)
334+
enddef
335+
322336
def Test_skipped_expr_linebreak()
323337
if 0
324338
var x = []

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+
2396,
753755
/**/
754756
2395,
755757
/**/

0 commit comments

Comments
 (0)