Skip to content

Commit 5ca5cc6

Browse files
committed
patch 8.2.3371: Vim9: :$ENV cannot be followed by ->func() in next line
Problem: Vim9: :$ENV cannot be followed by ->func() in next line. Solution: Use "$ENV" as the start of an expression. (closes #8790)
1 parent 60faf86 commit 5ca5cc6

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/ex_docmd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,14 +3425,16 @@ find_ex_command(
34253425
{
34263426
char_u *pskip = skip_option_env_lead(eap->cmd);
34273427

3428-
if (vim_strchr((char_u *)"{('[\"@&", *p) != NULL
3428+
if (vim_strchr((char_u *)"{('[\"@&$", *p) != NULL
34293429
|| ((p = to_name_const_end(pskip)) > eap->cmd && *p != NUL))
34303430
{
34313431
int oplen;
34323432
int heredoc;
34333433
char_u *swp;
34343434

3435-
if (*eap->cmd == '&' || (eap->cmd[0] == '@'
3435+
if (*eap->cmd == '&'
3436+
|| *eap->cmd == '$'
3437+
|| (eap->cmd[0] == '@'
34363438
&& (valid_yank_reg(eap->cmd[1], FALSE)
34373439
|| eap->cmd[1] == '@')))
34383440
{
@@ -3443,12 +3445,14 @@ find_ex_command(
34433445
p += 2;
34443446
p = to_name_end(p, FALSE);
34453447
}
3448+
else if (*eap->cmd == '$')
3449+
p = to_name_end(eap->cmd + 1, FALSE);
34463450
else
34473451
p = eap->cmd + 2;
34483452
if (ends_excmd(*skipwhite(p)))
34493453
{
3450-
// "&option <NL>" and "@r <NL>" is the start of an
3451-
// expression.
3454+
// "&option <NL>", "$ENV <NL>" and "@r <NL>" are the start
3455+
// of an expression.
34523456
eap->cmdidx = CMD_eval;
34533457
return eap->cmd;
34543458
}

src/testdir/test_vim9_cmd.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,22 @@ def Test_register_use_linebreak()
553553
CheckDefAndScriptSuccess(lines)
554554
enddef
555555

556+
def Test_environment_use_linebreak()
557+
var lines =<< trim END
558+
new
559+
$TESTENV = 'one'
560+
$TESTENV->setline(1)
561+
$TESTENV = 'two'
562+
$TESTENV ->setline(2)
563+
$TESTENV = 'three'
564+
$TESTENV
565+
->setline(3)
566+
assert_equal(['one', 'two', 'three'], getline(1, '$'))
567+
bwipe!
568+
END
569+
CheckDefAndScriptSuccess(lines)
570+
enddef
571+
556572
def Test_skipped_expr_linebreak()
557573
if 0
558574
var x = []

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3371,
758760
/**/
759761
3370,
760762
/**/

src/vim9compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9745,9 +9745,11 @@ compile_def_function(
97459745
* COMMAND after range
97469746
* 'text'->func() should not be confused with 'a mark
97479747
* "++nr" and "--nr" are eval commands
9748+
* in "$ENV->func()" the "$" is not a range
97489749
*/
97499750
cmd = ea.cmd;
97509751
if (!(local_cmdmod.cmod_flags & CMOD_LEGACY)
9752+
&& (*cmd != '$' || starts_with_colon)
97519753
&& (starts_with_colon || !(*cmd == '\''
97529754
|| (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-')))))
97539755
{

0 commit comments

Comments
 (0)