Patch 8.2.2137

4 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 13, 2020, 8:25:10 AM12/13/20
to vim...@googlegroups.com

Patch 8.2.2137
Problem: Vim9: :echo and :execute give error for empty argument.
Solution: Ignore an empty argument. (closes #7468)
Files: src/vim9compile.c, src/errors.h, src/testdir/test_vim9_script.vim,
src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.2136/src/vim9compile.c 2020-12-12 14:33:37.096920916 +0100
--- src/vim9compile.c 2020-12-13 14:08:37.258104777 +0100
***************
*** 3975,3981 ****

if (!eval_isnamec1(**arg))
{
! semsg(_(e_name_expected), *arg);
return FAIL;
}

--- 3975,3984 ----

if (!eval_isnamec1(**arg))
{
! if (ends_excmd(*skipwhite(*arg)))
! semsg(_(e_empty_expression_str), *arg);
! else
! semsg(_(e_name_expected_str), *arg);
return FAIL;
}

***************
*** 7101,7128 ****
compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
{
char_u *p = arg;
! char_u *prev;
int count = 0;

for (;;)
{
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
++count;
prev = p;
p = skipwhite(p);
- if (ends_excmd2(prev, p))
- break;
}

! if (cmdidx == CMD_echo || cmdidx == CMD_echon)
! generate_ECHO(cctx, cmdidx == CMD_echo, count);
! else if (cmdidx == CMD_execute)
! generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
! else if (cmdidx == CMD_echomsg)
! generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
! else
! generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
return p;
}

--- 7104,7134 ----
compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
{
char_u *p = arg;
! char_u *prev = arg;
int count = 0;

for (;;)
{
+ if (ends_excmd2(prev, p))
+ break;
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
++count;
prev = p;
p = skipwhite(p);
}

! if (count > 0)
! {
! if (cmdidx == CMD_echo || cmdidx == CMD_echon)
! generate_ECHO(cctx, cmdidx == CMD_echo, count);
! else if (cmdidx == CMD_execute)
! generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
! else if (cmdidx == CMD_echomsg)
! generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
! else
! generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
! }
return p;
}

*** ../vim-8.2.2136/src/errors.h 2020-12-12 18:58:36.788284026 +0100
--- src/errors.h 2020-12-13 14:08:44.210081315 +0100
***************
*** 61,67 ****
INIT(= N_("E1013: Argument %d: type mismatch, expected %s but got %s"));
EXTERN char e_invalid_key_str[]
INIT(= N_("E1014: Invalid key: %s"));
! EXTERN char e_name_expected[]
INIT(= N_("E1015: Name expected: %s"));
EXTERN char e_cannot_declare_a_scope_variable[]
INIT(= N_("E1016: Cannot declare a %s variable: %s"));
--- 61,67 ----
INIT(= N_("E1013: Argument %d: type mismatch, expected %s but got %s"));
EXTERN char e_invalid_key_str[]
INIT(= N_("E1014: Invalid key: %s"));
! EXTERN char e_name_expected_str[]
INIT(= N_("E1015: Name expected: %s"));
EXTERN char e_cannot_declare_a_scope_variable[]
INIT(= N_("E1016: Cannot declare a %s variable: %s"));
***************
*** 315,317 ****
--- 315,319 ----
INIT(= N_("E1141: Indexable type required"));
EXTERN char e_non_empty_string_required[]
INIT(= N_("E1142: Non-empty string required"));
+ EXTERN char e_empty_expression_str[]
+ INIT(= N_("E1143: empty expression: \"%s\""));
*** ../vim-8.2.2136/src/testdir/test_vim9_script.vim 2020-12-12 21:25:52.837244962 +0100
--- src/testdir/test_vim9_script.vim 2020-12-13 14:16:44.984490311 +0100
***************
*** 620,626 ****
CheckDefFailure(['if 1', 'endtry'], 'E171:')
CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')

! CheckDefFailure(['throw'], 'E1015:')
CheckDefFailure(['throw xxx'], 'E1001:')
enddef

--- 620,626 ----
CheckDefFailure(['if 1', 'endtry'], 'E171:')
CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')

! CheckDefFailure(['throw'], 'E1143:')
CheckDefFailure(['throw xxx'], 'E1001:')
enddef

***************
*** 1719,1724 ****
--- 1719,1728 ----
enddef

def Test_execute_cmd()
+ # missing argument is ignored
+ execute
+ execute # comment
+
new
setline(1, 'default')
execute 'setline(1, "execute-string")'
***************
*** 2137,2145 ****
'vim9script',
'exe "echo"# something',
], 'E121:')
- CheckDefFailure([
- 'exe # comment',
- ], 'E1015:')
CheckScriptFailure([
'vim9script',
'exe# something',
--- 2141,2146 ----
***************
*** 2164,2170 ****
' throw#comment',
'catch',
'endtry',
! ], 'E1015:')
CheckDefFailure([
'try',
' throw "yes"#comment',
--- 2165,2171 ----
' throw#comment',
'catch',
'endtry',
! ], 'E1143:')
CheckDefFailure([
'try',
' throw "yes"#comment',
*** ../vim-8.2.2136/src/testdir/test_vim9_disassemble.vim 2020-12-10 19:43:36.629155311 +0100
--- src/testdir/test_vim9_disassemble.vim 2020-12-13 13:55:29.408874032 +0100
***************
*** 15,20 ****
--- 15,21 ----
def s:ScriptFuncLoad(arg: string)
var local = 1
buffers
+ echo
echo arg
echo local
echo &lines
***************
*** 43,56 ****

var res = execute('disass s:ScriptFuncLoad')
assert_match('<SNR>\d*_ScriptFuncLoad.*' ..
! 'buffers.*' ..
! ' EXEC \+buffers.*' ..
! ' LOAD arg\[-1\].*' ..
! ' LOAD $0.*' ..
! ' LOADOPT &lines.*' ..
! ' LOADV v:version.*' ..
! ' LOADS s:scriptvar from .*test_vim9_disassemble.vim.*' ..
! ' LOADG g:globalvar.*' ..
'echo get(g:, "global")\_s*' ..
'\d\+ LOAD g:\_s*' ..
'\d\+ PUSHS "global"\_s*' ..
--- 44,70 ----

var res = execute('disass s:ScriptFuncLoad')
assert_match('<SNR>\d*_ScriptFuncLoad.*' ..
! 'buffers\_s*' ..
! '\d\+ EXEC \+buffers\_s*' ..
! 'echo\_s*' ..
! 'echo arg\_s*' ..
! '\d\+ LOAD arg\[-1\]\_s*' ..
! '\d\+ ECHO 1\_s*' ..
! 'echo local\_s*' ..
! '\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*' ..
'\d\+ LOAD g:\_s*' ..
'\d\+ PUSHS "global"\_s*' ..
*** ../vim-8.2.2136/src/version.c 2020-12-13 12:25:32.080270459 +0100
--- src/version.c 2020-12-13 14:00:04.619903295 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2137,
/**/

--
God made machine language; all the rest is the work of man.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages