Skip to content

Commit df069ee

Browse files
committed
patch 8.2.1042: Vim9: cannot put an operator on the next line
Problem: Vim9: cannot put an operator on the next line. Solution: Require a colon before a range to see if that causes problems.
1 parent 7eaafe6 commit df069ee

7 files changed

Lines changed: 59 additions & 25 deletions

File tree

runtime/doc/vim9.txt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9.txt* For Vim version 8.2. Last change: 2020 Jun 21
1+
*vim9.txt* For Vim version 8.2. Last change: 2020 Jun 22
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -257,27 +257,32 @@ Function call: >
257257
arg2
258258
)
259259
260-
For binary operators iin expressions not in [], {} or () a line break is
261-
possible AFTER the operators. For example: >
262-
let text = lead ..
263-
middle ..
264-
end
260+
For binary operators in expressions not in [], {} or () a line break is
261+
possible just before or after the operator. For example: >
262+
let text = lead
263+
.. middle
264+
.. end
265265
let total = start +
266266
end -
267267
correction
268-
let result = positive ?
269-
PosFunc(arg) :
270-
NegFunc(arg)
268+
let result = positive
269+
? PosFunc(arg)
270+
: NegFunc(arg)
271271
272-
A special case is "->" for function call chains, it can appear in the next
273-
line: >
274272
let result = GetBuilder()
275273
->BuilderSetWidth(333)
276274
->BuilderSetHeight(777)
277275
->BuilderBuild()
278276
279-
Note that "enddef" cannot be used at the start of a continuation line, it ends
280-
the current function.
277+
< *E1050*
278+
To make it possible for the operator at the start of the line to be
279+
recognized, it is required to put a colon before a range. This will adde
280+
"start" and print: >
281+
let result = start
282+
+ print
283+
This will assign "start" and print a line: >
284+
let result = start
285+
:+ print
281286
282287
It is also possible to split a function header over multiple lines, in between
283288
arguments: >
@@ -286,6 +291,9 @@ arguments: >
286291
separator = '-'
287292
): string
288293
294+
Note that "enddef" cannot be used at the start of a continuation line, it ends
295+
the current function.
296+
289297

290298
No curly braces expansion ~
291299

src/ex_docmd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,14 @@ do_one_cmd(
17291729

17301730
#ifdef FEAT_EVAL
17311731
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && !starts_with_colon)
1732+
{
1733+
if (ea.cmd > cmd)
1734+
{
1735+
emsg(_(e_colon_required));
1736+
goto doend;
1737+
}
17321738
p = find_ex_command(&ea, NULL, lookup_scriptvar, NULL);
1739+
}
17331740
else
17341741
#endif
17351742
p = find_ex_command(&ea, NULL, NULL, NULL);
@@ -3446,7 +3453,7 @@ excmd_get_argt(cmdidx_T idx)
34463453
* Backslashed delimiters after / or ? will be skipped, and commands will
34473454
* not be expanded between /'s and ?'s or after "'".
34483455
*
3449-
* Also skip white space and ":" characters.
3456+
* Also skip white space and ":" characters after the range.
34503457
* Returns the "cmd" pointer advanced to beyond the range.
34513458
*/
34523459
char_u *

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ EXTERN char e_const_req_value[] INIT(= N_("E1021: const requires a value"));
17901790
EXTERN char e_type_req[] INIT(= N_("E1022: type or initialization required"));
17911791
EXTERN char e_declare_var[] INIT(= N_("E1016: Cannot declare a %s variable: %s"));
17921792
EXTERN char e_declare_env_var[] INIT(= N_("E1016: Cannot declare an environment variable: %s"));
1793+
EXTERN char e_colon_required[] INIT(= N_("E1050: Colon required before a range"));
17931794
#endif
17941795
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
17951796
EXTERN char e_alloc_color[] INIT(= N_("E254: Cannot allocate color %s"));

src/testdir/test_vim9_expr.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,12 @@ func Test_expr5_fails()
585585
call CheckDefFailure(["let x = '1' ..'2'"], msg)
586586
call CheckDefFailure(["let x = '1'.. '2'"], msg)
587587

588-
call CheckDefFailure(["let x = 0z1122 + 33"], 'E1035')
589-
call CheckDefFailure(["let x = 0z1122 + [3]"], 'E1035')
590-
call CheckDefFailure(["let x = 0z1122 + 'asd'"], 'E1035')
591-
call CheckDefFailure(["let x = 33 + 0z1122"], 'E1035')
592-
call CheckDefFailure(["let x = [3] + 0z1122"], 'E1035')
593-
call CheckDefFailure(["let x = 'asdf' + 0z1122"], 'E1035')
588+
call CheckDefFailure(["let x = 0z1122 + 33"], 'E1051')
589+
call CheckDefFailure(["let x = 0z1122 + [3]"], 'E1051')
590+
call CheckDefFailure(["let x = 0z1122 + 'asd'"], 'E1051')
591+
call CheckDefFailure(["let x = 33 + 0z1122"], 'E1051')
592+
call CheckDefFailure(["let x = [3] + 0z1122"], 'E1051')
593+
call CheckDefFailure(["let x = 'asdf' + 0z1122"], 'E1051')
594594
call CheckDefFailure(["let x = 6 + xxx"], 'E1001')
595595
endfunc
596596

src/testdir/test_vim9_script.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ func Test_const()
468468
call CheckDefFailure(['const &option'], 'E996:')
469469
endfunc
470470

471+
def Test_range_no_colon()
472+
call CheckDefFailure(['%s/a/b/'], 'E1050:')
473+
call CheckDefFailure(['+ s/a/b/'], 'E1050:')
474+
call CheckDefFailure(['- s/a/b/'], 'E1050:')
475+
call CheckDefFailure(['. s/a/b/'], 'E1050:')
476+
enddef
477+
478+
471479
def Test_block()
472480
let outer = 1
473481
{
@@ -1279,7 +1287,7 @@ def Test_echomsg_cmd()
12791287
echomsg 'some' 'more' # comment
12801288
assert_match('^some more$', Screenline(&lines))
12811289
echo 'clear'
1282-
1messages
1290+
:1messages
12831291
assert_match('^some more$', Screenline(&lines))
12841292

12851293
call CheckDefFailure(['echomsg "xxx"# comment'], 'E488:')
@@ -1898,7 +1906,7 @@ def Test_vim9_comment_not_compiled()
18981906
'vim9script',
18991907
'new'
19001908
'call setline(1, ["# define pat", "last"])',
1901-
'$',
1909+
':$',
19021910
'dsearch /pat/ #comment',
19031911
'bwipe!',
19041912
])
@@ -1907,7 +1915,7 @@ def Test_vim9_comment_not_compiled()
19071915
'vim9script',
19081916
'new'
19091917
'call setline(1, ["# define pat", "last"])',
1910-
'$',
1918+
':$',
19111919
'dsearch /pat/#comment',
19121920
'bwipe!',
19131921
], 'E488:')

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1042,
757759
/**/
758760
1041,
759761
/**/

src/vim9compile.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ check_number_or_float(vartype_T type1, vartype_T type2, char_u *op)
643643
|| type2 == VAR_ANY)))
644644
{
645645
if (*op == '+')
646-
emsg(_("E1035: wrong argument type for +"));
646+
emsg(_("E1051: wrong argument type for +"));
647647
else
648648
semsg(_("E1036: %c requires number or float arguments"), *op);
649649
return FAIL;
@@ -6695,6 +6695,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
66956695
{
66966696
exarg_T ea;
66976697
int starts_with_colon = FALSE;
6698+
char_u *cmd;
66986699

66996700
// Bail out on the first error to avoid a flood of errors and report
67006701
// the right line number when inside try/catch.
@@ -6853,7 +6854,13 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
68536854
/*
68546855
* COMMAND after range
68556856
*/
6857+
cmd = ea.cmd;
68566858
ea.cmd = skip_range(ea.cmd, NULL);
6859+
if (ea.cmd > cmd && !starts_with_colon)
6860+
{
6861+
emsg(_(e_colon_required));
6862+
goto erret;
6863+
}
68576864
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
68586865
: (void *(*)(char_u *, size_t, cctx_T *))lookup_local,
68596866
&cctx);
@@ -7008,8 +7015,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
70087015
line = compile_mult_expr(p, ea.cmdidx, &cctx);
70097016
break;
70107017

7018+
// TODO: other commands with an expression argument
7019+
70117020
default:
7012-
// TODO: other commands with an expression argument
70137021
// Not recognized, execute with do_cmdline_cmd().
70147022
ea.arg = p;
70157023
line = compile_exec(line, &ea, &cctx);

0 commit comments

Comments
 (0)