0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2020-12-13 14:19:25 +01:00
parent c530852315
commit e498429087
5 changed files with 51 additions and 26 deletions

View File

@@ -61,7 +61,7 @@ EXTERN char e_argument_nr_type_mismatch_expected_str_but_got_str[]
INIT(= N_("E1013: Argument %d: type mismatch, expected %s but got %s")); INIT(= N_("E1013: Argument %d: type mismatch, expected %s but got %s"));
EXTERN char e_invalid_key_str[] EXTERN char e_invalid_key_str[]
INIT(= N_("E1014: Invalid key: %s")); INIT(= N_("E1014: Invalid key: %s"));
EXTERN char e_name_expected[] EXTERN char e_name_expected_str[]
INIT(= N_("E1015: Name expected: %s")); INIT(= N_("E1015: Name expected: %s"));
EXTERN char e_cannot_declare_a_scope_variable[] EXTERN char e_cannot_declare_a_scope_variable[]
INIT(= N_("E1016: Cannot declare a %s variable: %s")); INIT(= N_("E1016: Cannot declare a %s variable: %s"));
@@ -315,3 +315,5 @@ EXTERN char e_indexable_type_required[]
INIT(= N_("E1141: Indexable type required")); INIT(= N_("E1141: Indexable type required"));
EXTERN char e_non_empty_string_required[] EXTERN char e_non_empty_string_required[]
INIT(= N_("E1142: Non-empty string required")); INIT(= N_("E1142: Non-empty string required"));
EXTERN char e_empty_expression_str[]
INIT(= N_("E1143: empty expression: \"%s\""));

View File

@@ -15,6 +15,7 @@ let t:tabpagevar = 't'
def s:ScriptFuncLoad(arg: string) def s:ScriptFuncLoad(arg: string)
var local = 1 var local = 1
buffers buffers
echo
echo arg echo arg
echo local echo local
echo &lines echo &lines
@@ -43,14 +44,27 @@ def Test_disassemble_load()
var res = execute('disass s:ScriptFuncLoad') var res = execute('disass s:ScriptFuncLoad')
assert_match('<SNR>\d*_ScriptFuncLoad.*' .. assert_match('<SNR>\d*_ScriptFuncLoad.*' ..
'buffers.*' .. 'buffers\_s*' ..
' EXEC \+buffers.*' .. '\d\+ EXEC \+buffers\_s*' ..
' LOAD arg\[-1\].*' .. 'echo\_s*' ..
' LOAD $0.*' .. 'echo arg\_s*' ..
' LOADOPT &lines.*' .. '\d\+ LOAD arg\[-1\]\_s*' ..
' LOADV v:version.*' .. '\d\+ ECHO 1\_s*' ..
' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' .. 'echo local\_s*' ..
' LOADG g:globalvar.*' .. '\d\+ LOAD $0\_s*' ..
'\d\+ ECHO 1\_s*' ..
'echo &lines\_s*' ..
'\d\+ LOADOPT &lines\_s*' ..
'\d\+ ECHO 1\_s*' ..
'echo v:version\_s*' ..
'\d\+ LOADV v:version\_s*' ..
'\d\+ ECHO 1\_s*' ..
'echo s:scriptvar\_s*' ..
'\d\+ LOADS s:scriptvar from .*test_vim9_disassemble.vim\_s*' ..
'\d\+ ECHO 1\_s*' ..
'echo g:globalvar\_s*' ..
'\d\+ LOADG g:globalvar\_s*' ..
'\d\+ ECHO 1\_s*' ..
'echo get(g:, "global")\_s*' .. 'echo get(g:, "global")\_s*' ..
'\d\+ LOAD g:\_s*' .. '\d\+ LOAD g:\_s*' ..
'\d\+ PUSHS "global"\_s*' .. '\d\+ PUSHS "global"\_s*' ..

View File

@@ -620,7 +620,7 @@ def Test_try_catch_fails()
CheckDefFailure(['if 1', 'endtry'], 'E171:') CheckDefFailure(['if 1', 'endtry'], 'E171:')
CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:') CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
CheckDefFailure(['throw'], 'E1015:') CheckDefFailure(['throw'], 'E1143:')
CheckDefFailure(['throw xxx'], 'E1001:') CheckDefFailure(['throw xxx'], 'E1001:')
enddef enddef
@@ -1719,6 +1719,10 @@ def Test_nested_if()
enddef enddef
def Test_execute_cmd() def Test_execute_cmd()
# missing argument is ignored
execute
execute # comment
new new
setline(1, 'default') setline(1, 'default')
execute 'setline(1, "execute-string")' execute 'setline(1, "execute-string")'
@@ -2137,9 +2141,6 @@ def Test_vim9_comment()
'vim9script', 'vim9script',
'exe "echo"# something', 'exe "echo"# something',
], 'E121:') ], 'E121:')
CheckDefFailure([
'exe # comment',
], 'E1015:')
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'exe# something', 'exe# something',
@@ -2164,7 +2165,7 @@ def Test_vim9_comment()
' throw#comment', ' throw#comment',
'catch', 'catch',
'endtry', 'endtry',
], 'E1015:') ], 'E1143:')
CheckDefFailure([ CheckDefFailure([
'try', 'try',
' throw "yes"#comment', ' throw "yes"#comment',

View File

@@ -750,6 +750,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 */
/**/
2137,
/**/ /**/
2136, 2136,
/**/ /**/

View File

@@ -3975,7 +3975,10 @@ compile_expr7(
if (!eval_isnamec1(**arg)) if (!eval_isnamec1(**arg))
{ {
semsg(_(e_name_expected), *arg); if (ends_excmd(*skipwhite(*arg)))
semsg(_(e_empty_expression_str), *arg);
else
semsg(_(e_name_expected_str), *arg);
return FAIL; return FAIL;
} }
@@ -7101,28 +7104,31 @@ compile_throw(char_u *arg, cctx_T *cctx UNUSED)
compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx) compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
{ {
char_u *p = arg; char_u *p = arg;
char_u *prev; char_u *prev = arg;
int count = 0; int count = 0;
for (;;) for (;;)
{ {
if (ends_excmd2(prev, p))
break;
if (compile_expr0(&p, cctx) == FAIL) if (compile_expr0(&p, cctx) == FAIL)
return NULL; return NULL;
++count; ++count;
prev = p; prev = p;
p = skipwhite(p); p = skipwhite(p);
if (ends_excmd2(prev, p))
break;
} }
if (cmdidx == CMD_echo || cmdidx == CMD_echon) if (count > 0)
generate_ECHO(cctx, cmdidx == CMD_echo, count); {
else if (cmdidx == CMD_execute) if (cmdidx == CMD_echo || cmdidx == CMD_echon)
generate_MULT_EXPR(cctx, ISN_EXECUTE, count); generate_ECHO(cctx, cmdidx == CMD_echo, count);
else if (cmdidx == CMD_echomsg) else if (cmdidx == CMD_execute)
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count); generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
else else if (cmdidx == CMD_echomsg)
generate_MULT_EXPR(cctx, ISN_ECHOERR, count); generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
else
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
}
return p; return p;
} }