Skip to content

Commit e498429

Browse files
committed
patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Problem: Vim9: :echo and :execute give error for empty argument. Solution: Ignore an empty argument. (closes #7468)
1 parent c530852 commit e498429

5 files changed

Lines changed: 51 additions & 26 deletions

File tree

src/errors.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ EXTERN char e_argument_nr_type_mismatch_expected_str_but_got_str[]
6161
INIT(= N_("E1013: Argument %d: type mismatch, expected %s but got %s"));
6262
EXTERN char e_invalid_key_str[]
6363
INIT(= N_("E1014: Invalid key: %s"));
64-
EXTERN char e_name_expected[]
64+
EXTERN char e_name_expected_str[]
6565
INIT(= N_("E1015: Name expected: %s"));
6666
EXTERN char e_cannot_declare_a_scope_variable[]
6767
INIT(= N_("E1016: Cannot declare a %s variable: %s"));
@@ -315,3 +315,5 @@ EXTERN char e_indexable_type_required[]
315315
INIT(= N_("E1141: Indexable type required"));
316316
EXTERN char e_non_empty_string_required[]
317317
INIT(= N_("E1142: Non-empty string required"));
318+
EXTERN char e_empty_expression_str[]
319+
INIT(= N_("E1143: empty expression: \"%s\""));

src/testdir/test_vim9_disassemble.vim

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let t:tabpagevar = 't'
1515
def s:ScriptFuncLoad(arg: string)
1616
var local = 1
1717
buffers
18+
echo
1819
echo arg
1920
echo local
2021
echo &lines
@@ -43,14 +44,27 @@ def Test_disassemble_load()
4344

4445
var res = execute('disass s:ScriptFuncLoad')
4546
assert_match('<SNR>\d*_ScriptFuncLoad.*' ..
46-
'buffers.*' ..
47-
' EXEC \+buffers.*' ..
48-
' LOAD arg\[-1\].*' ..
49-
' LOAD $0.*' ..
50-
' LOADOPT &lines.*' ..
51-
' LOADV v:version.*' ..
52-
' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' ..
53-
' LOADG g:globalvar.*' ..
47+
'buffers\_s*' ..
48+
'\d\+ EXEC \+buffers\_s*' ..
49+
'echo\_s*' ..
50+
'echo arg\_s*' ..
51+
'\d\+ LOAD arg\[-1\]\_s*' ..
52+
'\d\+ ECHO 1\_s*' ..
53+
'echo local\_s*' ..
54+
'\d\+ LOAD $0\_s*' ..
55+
'\d\+ ECHO 1\_s*' ..
56+
'echo &lines\_s*' ..
57+
'\d\+ LOADOPT &lines\_s*' ..
58+
'\d\+ ECHO 1\_s*' ..
59+
'echo v:version\_s*' ..
60+
'\d\+ LOADV v:version\_s*' ..
61+
'\d\+ ECHO 1\_s*' ..
62+
'echo s:scriptvar\_s*' ..
63+
'\d\+ LOADS s:scriptvar from .*test_vim9_disassemble.vim\_s*' ..
64+
'\d\+ ECHO 1\_s*' ..
65+
'echo g:globalvar\_s*' ..
66+
'\d\+ LOADG g:globalvar\_s*' ..
67+
'\d\+ ECHO 1\_s*' ..
5468
'echo get(g:, "global")\_s*' ..
5569
'\d\+ LOAD g:\_s*' ..
5670
'\d\+ PUSHS "global"\_s*' ..

src/testdir/test_vim9_script.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def Test_try_catch_fails()
620620
CheckDefFailure(['if 1', 'endtry'], 'E171:')
621621
CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
622622

623-
CheckDefFailure(['throw'], 'E1015:')
623+
CheckDefFailure(['throw'], 'E1143:')
624624
CheckDefFailure(['throw xxx'], 'E1001:')
625625
enddef
626626

@@ -1719,6 +1719,10 @@ def Test_nested_if()
17191719
enddef
17201720

17211721
def Test_execute_cmd()
1722+
# missing argument is ignored
1723+
execute
1724+
execute # comment
1725+
17221726
new
17231727
setline(1, 'default')
17241728
execute 'setline(1, "execute-string")'
@@ -2137,9 +2141,6 @@ def Test_vim9_comment()
21372141
'vim9script',
21382142
'exe "echo"# something',
21392143
], 'E121:')
2140-
CheckDefFailure([
2141-
'exe # comment',
2142-
], 'E1015:')
21432144
CheckScriptFailure([
21442145
'vim9script',
21452146
'exe# something',
@@ -2164,7 +2165,7 @@ def Test_vim9_comment()
21642165
' throw#comment',
21652166
'catch',
21662167
'endtry',
2167-
], 'E1015:')
2168+
], 'E1143:')
21682169
CheckDefFailure([
21692170
'try',
21702171
' throw "yes"#comment',

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+
2137,
753755
/**/
754756
2136,
755757
/**/

src/vim9compile.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,7 +3975,10 @@ compile_expr7(
39753975

39763976
if (!eval_isnamec1(**arg))
39773977
{
3978-
semsg(_(e_name_expected), *arg);
3978+
if (ends_excmd(*skipwhite(*arg)))
3979+
semsg(_(e_empty_expression_str), *arg);
3980+
else
3981+
semsg(_(e_name_expected_str), *arg);
39793982
return FAIL;
39803983
}
39813984

@@ -7101,28 +7104,31 @@ compile_throw(char_u *arg, cctx_T *cctx UNUSED)
71017104
compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
71027105
{
71037106
char_u *p = arg;
7104-
char_u *prev;
7107+
char_u *prev = arg;
71057108
int count = 0;
71067109

71077110
for (;;)
71087111
{
7112+
if (ends_excmd2(prev, p))
7113+
break;
71097114
if (compile_expr0(&p, cctx) == FAIL)
71107115
return NULL;
71117116
++count;
71127117
prev = p;
71137118
p = skipwhite(p);
7114-
if (ends_excmd2(prev, p))
7115-
break;
71167119
}
71177120

7118-
if (cmdidx == CMD_echo || cmdidx == CMD_echon)
7119-
generate_ECHO(cctx, cmdidx == CMD_echo, count);
7120-
else if (cmdidx == CMD_execute)
7121-
generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
7122-
else if (cmdidx == CMD_echomsg)
7123-
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
7124-
else
7125-
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
7121+
if (count > 0)
7122+
{
7123+
if (cmdidx == CMD_echo || cmdidx == CMD_echon)
7124+
generate_ECHO(cctx, cmdidx == CMD_echo, count);
7125+
else if (cmdidx == CMD_execute)
7126+
generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
7127+
else if (cmdidx == CMD_echomsg)
7128+
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
7129+
else
7130+
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
7131+
}
71267132
return p;
71277133
}
71287134

0 commit comments

Comments
 (0)