patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
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.
diff --git a/src/eval.c b/src/eval.c
index bf9e8ee..aa3d0a1 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2951,7 +2951,8 @@
if (vim9script && (var2.v_type == VAR_VOID
|| var2.v_type == VAR_CHANNEL
|| var2.v_type == VAR_JOB))
- emsg(_(e_inval_string));
+ 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,7 +6111,7 @@
{
char_u *arg = eap->arg;
typval_T rettv;
- char_u *p;
+ char_u *arg_start;
int needclr = TRUE;
int atstart = TRUE;
int did_emsg_before = did_emsg;
@@ -6127,7 +6128,7 @@
// still need to be cleared. E.g., "echo 22,44".
need_clr_eos = needclr;
- p = arg;
+ arg_start = arg;
if (eval1(&arg, &rettv, &evalarg) == FAIL)
{
/*
@@ -6137,14 +6138,21 @@
*/
if (!aborting() && did_emsg == did_emsg_before
&& called_emsg == called_emsg_before)
- semsg(_(e_invexpr2), p);
+ 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,7 +6226,8 @@
{
if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
{
- emsg(_(e_inval_string));
+ semsg(_(e_using_invalid_value_as_string_str),
+ vartype_name(rettv.v_type));
p = NULL;
}
else