1
0
forked from aniani/vim

patch 8.2.1278: Vim9: line break after "->" only allowed in :def function

Problem:    Vim9: line break after "->" only allowed in :def function.
Solution:   Only allow line break after "->". (closes #6492)
This commit is contained in:
Bram Moolenaar
2020-07-23 15:38:03 +02:00
parent 7a87b4e3fe
commit dd1a9af00f
4 changed files with 16 additions and 6 deletions

View File

@@ -1730,6 +1730,7 @@ EXTERN char e_longname[] INIT(= N_("E75: Name too long"));
EXTERN char e_toomsbra[] INIT(= N_("E76: Too many [")); EXTERN char e_toomsbra[] INIT(= N_("E76: Too many ["));
EXTERN char e_toomany[] INIT(= N_("E77: Too many file names")); EXTERN char e_toomany[] INIT(= N_("E77: Too many file names"));
EXTERN char e_trailing[] INIT(= N_("E488: Trailing characters")); EXTERN char e_trailing[] INIT(= N_("E488: Trailing characters"));
EXTERN char e_trailing_arg[] INIT(= N_("E488: Trailing characters: %s"));
EXTERN char e_umark[] INIT(= N_("E78: Unknown mark")); EXTERN char e_umark[] INIT(= N_("E78: Unknown mark"));
EXTERN char e_wildexpand[] INIT(= N_("E79: Cannot expand wildcards")); EXTERN char e_wildexpand[] INIT(= N_("E79: Cannot expand wildcards"));
EXTERN char e_winheight[] INIT(= N_("E591: 'winheight' cannot be smaller than 'winminheight'")); EXTERN char e_winheight[] INIT(= N_("E591: 'winheight' cannot be smaller than 'winminheight'"));

View File

@@ -1460,7 +1460,8 @@ enddef
def Test_expr7_call() def Test_expr7_call()
assert_equal('yes', 'yes'->Echo()) assert_equal('yes', 'yes'->Echo())
assert_equal('yes', 'yes'->s:EchoArg()) assert_equal('yes', 'yes'
->s:EchoArg())
assert_equal(1, !range(5)->empty()) assert_equal(1, !range(5)->empty())
assert_equal([0, 1, 2], --3->range()) assert_equal([0, 1, 2], --3->range())
@@ -1531,6 +1532,8 @@ func Test_expr7_fails()
call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:') call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
call CheckDefFailure(["'yes'->", "Echo()"], 'E488:')
call CheckDefExecFailure(["[1, 2->len()"], 'E697:') call CheckDefExecFailure(["[1, 2->len()"], 'E697:')
call CheckDefExecFailure(["#{a: 1->len()"], 'E488:') call CheckDefExecFailure(["#{a: 1->len()"], 'E488:')
call CheckDefExecFailure(["{'a': 1->len()"], 'E723:') call CheckDefExecFailure(["{'a': 1->len()"], 'E723:')
@@ -1591,8 +1594,8 @@ enddef
def Test_expr7_subscript_linebreak() def Test_expr7_subscript_linebreak()
let range = range( let range = range(
3) 3)
let l = range-> let l = range
map('string(v:key)') ->map('string(v:key)')
assert_equal(['0', '1', '2'], l) assert_equal(['0', '1', '2'], l)
l = range l = range

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1278,
/**/ /**/
1277, 1277,
/**/ /**/

View File

@@ -3773,8 +3773,7 @@ compile_subscript(
p += 2; p += 2;
*arg = skipwhite(p); *arg = skipwhite(p);
if (may_get_next_line(p, arg, cctx) == FAIL) // No line break supported right after "->".
return FAIL;
if (**arg == '{') if (**arg == '{')
{ {
// lambda call: list->{lambda} // lambda call: list->{lambda}
@@ -3785,6 +3784,11 @@ compile_subscript(
{ {
// method call: list->method() // method call: list->method()
p = *arg; p = *arg;
if (!eval_isnamec1(*p))
{
semsg(_(e_trailing_arg), p);
return FAIL;
}
if (ASCII_ISALPHA(*p) && p[1] == ':') if (ASCII_ISALPHA(*p) && p[1] == ':')
p += 2; p += 2;
for ( ; eval_isnamec1(*p); ++p) for ( ; eval_isnamec1(*p); ++p)
@@ -7045,7 +7049,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
&& !(*line == '#' && (line == cctx.ctx_line_start && !(*line == '#' && (line == cctx.ctx_line_start
|| VIM_ISWHITE(line[-1])))) || VIM_ISWHITE(line[-1]))))
{ {
semsg(_("E488: Trailing characters: %s"), line); semsg(_(e_trailing_arg), line);
goto erret; goto erret;
} }
else else