Patch 8.2.2846
Problem: Vim9: "echo Func()" does not give an error for a function without
a return value.
Solution: Give an error. Be more specific about why a value is invalid.
Files: src/globals.h, src/errors.h, src/eval.c, src/evalfunc.c,
src/typval.c, src/vim9compile.c, src/vim9execute.c,
src/testdir/test_vim9_cmd.vim
*** ../vim-8.2.2845/src/globals.h 2021-05-01 17:45:59.992682570 +0200
--- src/globals.h 2021-05-09 23:10:32.986723331 +0200
***************
*** 1728,1734 ****
EXTERN char e_listdictarg[] INIT(= N_("E712: Argument of %s must be a List
or Dictionary"));
EXTERN char e_listdictblobarg[] INIT(= N_("E896: Argument of %s must be
a List, Dictionary or Blob"));
EXTERN char e_modulus[] INIT(= N_("E804: Cannot use '%' with
Float"));
- EXTERN char e_inval_string[] INIT(= N_("E908: using an invalid value as a
String"));
EXTERN char e_const_option[] INIT(= N_("E996: Cannot lock an option"));
EXTERN char e_unknown_option[] INIT(= N_("E113: Unknown option: %s"));
EXTERN char e_letunexp[] INIT(= N_("E18: Unexpected characters in
:let"));
--- 1728,1733 ----
*** ../vim-8.2.2845/src/errors.h 2021-04-25 16:35:52.101622736 +0200
--- src/errors.h 2021-05-09 23:10:32.986723331 +0200
***************
*** 31,36 ****
--- 31,38 ----
INIT(= N_("E719: Cannot slice a Dictionary"));
EXTERN char e_assert_fails_second_arg[]
INIT(= N_("E856: \"assert_fails()\" second argument must be a string or
a list with one or two strings"));
+ EXTERN char e_using_invalid_value_as_string_str[]
+ INIT(= N_("E908: using an invalid value as a String: %s"));
EXTERN char e_cannot_index_special_variable[]
INIT(= N_("E909: Cannot index a special variable"));
#endif
***************
*** 409,411 ****
--- 411,415 ----
INIT(= N_("E1185: Cannot nest :redir"));
EXTERN char e_missing_redir_end[]
INIT(= N_("E1185: Missing :redir END"));
+ EXTERN char e_expression_does_not_result_in_value_str[]
+ INIT(= N_("E1186: Expression does not result in a value: %s"));
*** ../vim-8.2.2845/src/eval.c 2021-05-07 17:55:51.967584415 +0200
--- src/eval.c 2021-05-09 23:10:32.986723331 +0200
***************
*** 2951,2957 ****
if (vim9script && (var2.v_type == VAR_VOID
|| var2.v_type == VAR_CHANNEL
|| var2.v_type == VAR_JOB))
! emsg(_(e_inval_string));
#ifdef FEAT_FLOAT
else if (vim9script && var2.v_type == VAR_FLOAT)
{
--- 2951,2958 ----
if (vim9script && (var2.v_type == VAR_VOID
|| var2.v_type == VAR_CHANNEL
|| var2.v_type == VAR_JOB))
! semsg(_(e_using_invalid_value_as_string_str),
! vartype_name(var2.v_type));
#ifdef FEAT_FLOAT
else if (vim9script && var2.v_type == VAR_FLOAT)
{
***************
*** 6110,6116 ****
{
char_u *arg = eap->arg;
typval_T rettv;
! char_u *p;
int needclr = TRUE;
int atstart = TRUE;
int did_emsg_before = did_emsg;
--- 6111,6117 ----
{
char_u *arg = eap->arg;
typval_T rettv;
! char_u *arg_start;
int needclr = TRUE;
int atstart = TRUE;
int did_emsg_before = did_emsg;
***************
*** 6127,6133 ****
// still need to be cleared. E.g., "echo 22,44".
need_clr_eos = needclr;
! p = arg;
if (eval1(&arg, &rettv, &evalarg) == FAIL)
{
/*
--- 6128,6134 ----
// still need to be cleared. E.g., "echo 22,44".
need_clr_eos = needclr;
! arg_start = arg;
if (eval1(&arg, &rettv, &evalarg) == FAIL)
{
/*
***************
*** 6137,6150 ****
*/
if (!aborting() && did_emsg == did_emsg_before
&& called_emsg == called_emsg_before)
! semsg(_(e_invexpr2), p);
need_clr_eos = FALSE;
break;
}
need_clr_eos = FALSE;
if (!eap->skip)
echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr);
clear_tv(&rettv);
arg = skipwhite(arg);
--- 6138,6158 ----
*/
if (!aborting() && did_emsg == did_emsg_before
&& called_emsg == called_emsg_before)
! semsg(_(e_invexpr2), arg_start);
need_clr_eos = FALSE;
break;
}
need_clr_eos = FALSE;
if (!eap->skip)
+ {
+ if (rettv.v_type == VAR_VOID)
+ {
+ semsg(_(e_expression_does_not_result_in_value_str), arg_start);
+ break;
+ }
echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr);
+ }
clear_tv(&rettv);
arg = skipwhite(arg);
***************
*** 6218,6224 ****
{
if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
{
! emsg(_(e_inval_string));
p = NULL;
}
else
--- 6226,6233 ----
{
if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
{
! semsg(_(e_using_invalid_value_as_string_str),
! vartype_name(rettv.v_type));
p = NULL;
}
else
*** ../vim-8.2.2845/src/evalfunc.c 2021-05-07 17:55:51.971584412 +0200
--- src/evalfunc.c 2021-05-09 23:10:32.986723331 +0200
***************
*** 3175,3181 ****
else if (argvars[arg_off].v_type == VAR_JOB
|| argvars[arg_off].v_type == VAR_CHANNEL)
{
! emsg(_(e_inval_string));
return;
}
else
--- 3175,3182 ----
else if (argvars[arg_off].v_type == VAR_JOB
|| argvars[arg_off].v_type == VAR_CHANNEL)
{
! semsg(_(e_using_invalid_value_as_string_str),
! vartype_name(argvars[arg_off].v_type));
return;
}
else
*** ../vim-8.2.2845/src/typval.c 2021-05-07 20:43:51.019580145 +0200
--- src/typval.c 2021-05-09 23:10:32.986723331 +0200
***************
*** 522,528 ****
case VAR_ANY:
case VAR_VOID:
case VAR_INSTR:
! emsg(_(e_inval_string));
break;
}
return NULL;
--- 522,529 ----
case VAR_ANY:
case VAR_VOID:
case VAR_INSTR:
! semsg(_(e_using_invalid_value_as_string_str),
! vartype_name(varp->v_type));
break;
}
return NULL;
*** ../vim-8.2.2845/src/vim9compile.c 2021-05-07 19:44:15.500477283 +0200
--- src/vim9compile.c 2021-05-09 23:10:32.990723319 +0200
***************
*** 8375,8389 ****
--- 8375,8405 ----
{
char_u *p = arg;
char_u *prev = arg;
+ char_u *expr_start;
int count = 0;
int start_ctx_lnum = cctx->ctx_lnum;
+ garray_T *stack = &cctx->ctx_type_stack;
+ type_T *type;
for (;;)
{
if (ends_excmd2(prev, p))
break;
+ expr_start = p;
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
+
+ if (cctx->ctx_skip != SKIP_YES)
+ {
+ // check for non-void type
+ type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
+ if (type->tt_type == VAR_VOID)
+ {
+ semsg(_(e_expression_does_not_result_in_value_str), expr_start);
+ return NULL;
+ }
+ }
+
++count;
prev = p;
p = skipwhite(p);
*** ../vim-8.2.2845/src/vim9execute.c 2021-05-07 17:55:51.967584415 +0200
--- src/vim9execute.c 2021-05-09 23:10:32.990723319 +0200
***************
*** 1578,1584 ****
|| tv->v_type == VAR_JOB)
{
SOURCING_LNUM = iptr->isn_lnum;
! emsg(_(e_inval_string));
break;
}
else
--- 1578,1585 ----
|| tv->v_type == VAR_JOB)
{
SOURCING_LNUM = iptr->isn_lnum;
! semsg(_(e_using_invalid_value_as_string_str),
! vartype_name(tv->v_type));
break;
}
else
*** ../vim-8.2.2845/src/testdir/test_vim9_cmd.vim 2021-05-06
17:36:50.988003911 +0200
--- src/testdir/test_vim9_cmd.vim 2021-05-09 23:10:32.986723331 +0200
***************
*** 1282,1286 ****
--- 1282,1309 ----
CheckDefFailure(lines, 'E1141:')
enddef
+ def Test_echo_void()
+ var lines =<< trim END
+ vim9script
+ def NoReturn()
+ echo 'nothing'
+ enddef
+ echo NoReturn()
+ END
+ CheckScriptFailure(lines, 'E1186:', 5)
+
+ lines =<< trim END
+ vim9script
+ def NoReturn()
+ echo 'nothing'
+ enddef
+ def Try()
+ echo NoReturn()
+ enddef
+ defcompile
+ END
+ CheckScriptFailure(lines, 'E1186:', 1)
+ enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.2845/src/version.c 2021-05-08 20:09:21.208327902 +0200
--- src/version.c 2021-05-09 23:09:29.334935729 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2846,
/**/
--
hundred-and-one symptoms of being an internet addict:
254. You wake up daily with your keyboard printed on your forehead.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202105092120.149LKmDh1966611%40masaka.moolenaar.net.