comparison src/eval.c @ 24614:07b3d21a8b4b v8.2.2846

patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void Commit: https://github.com/vim/vim/commit/68db996b621b98066fb7ab7028ed5c6aaa3954a8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 9 23:19:22 2021 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 May 2021 23:30:05 +0200
parents a4fda40e0bb9
children 4aebea72c397
comparison
equal deleted inserted replaced
24613:2ccff0c26a2f 24614:07b3d21a8b4b
2949 char_u *s2 = NULL; 2949 char_u *s2 = NULL;
2950 2950
2951 if (vim9script && (var2.v_type == VAR_VOID 2951 if (vim9script && (var2.v_type == VAR_VOID
2952 || var2.v_type == VAR_CHANNEL 2952 || var2.v_type == VAR_CHANNEL
2953 || var2.v_type == VAR_JOB)) 2953 || var2.v_type == VAR_JOB))
2954 emsg(_(e_inval_string)); 2954 semsg(_(e_using_invalid_value_as_string_str),
2955 vartype_name(var2.v_type));
2955 #ifdef FEAT_FLOAT 2956 #ifdef FEAT_FLOAT
2956 else if (vim9script && var2.v_type == VAR_FLOAT) 2957 else if (vim9script && var2.v_type == VAR_FLOAT)
2957 { 2958 {
2958 vim_snprintf((char *)buf2, NUMBUFLEN, "%g", 2959 vim_snprintf((char *)buf2, NUMBUFLEN, "%g",
2959 var2.vval.v_float); 2960 var2.vval.v_float);
6108 void 6109 void
6109 ex_echo(exarg_T *eap) 6110 ex_echo(exarg_T *eap)
6110 { 6111 {
6111 char_u *arg = eap->arg; 6112 char_u *arg = eap->arg;
6112 typval_T rettv; 6113 typval_T rettv;
6113 char_u *p; 6114 char_u *arg_start;
6114 int needclr = TRUE; 6115 int needclr = TRUE;
6115 int atstart = TRUE; 6116 int atstart = TRUE;
6116 int did_emsg_before = did_emsg; 6117 int did_emsg_before = did_emsg;
6117 int called_emsg_before = called_emsg; 6118 int called_emsg_before = called_emsg;
6118 evalarg_T evalarg; 6119 evalarg_T evalarg;
6125 { 6126 {
6126 // If eval1() causes an error message the text from the command may 6127 // If eval1() causes an error message the text from the command may
6127 // still need to be cleared. E.g., "echo 22,44". 6128 // still need to be cleared. E.g., "echo 22,44".
6128 need_clr_eos = needclr; 6129 need_clr_eos = needclr;
6129 6130
6130 p = arg; 6131 arg_start = arg;
6131 if (eval1(&arg, &rettv, &evalarg) == FAIL) 6132 if (eval1(&arg, &rettv, &evalarg) == FAIL)
6132 { 6133 {
6133 /* 6134 /*
6134 * Report the invalid expression unless the expression evaluation 6135 * Report the invalid expression unless the expression evaluation
6135 * has been cancelled due to an aborting error, an interrupt, or an 6136 * has been cancelled due to an aborting error, an interrupt, or an
6136 * exception. 6137 * exception.
6137 */ 6138 */
6138 if (!aborting() && did_emsg == did_emsg_before 6139 if (!aborting() && did_emsg == did_emsg_before
6139 && called_emsg == called_emsg_before) 6140 && called_emsg == called_emsg_before)
6140 semsg(_(e_invexpr2), p); 6141 semsg(_(e_invexpr2), arg_start);
6141 need_clr_eos = FALSE; 6142 need_clr_eos = FALSE;
6142 break; 6143 break;
6143 } 6144 }
6144 need_clr_eos = FALSE; 6145 need_clr_eos = FALSE;
6145 6146
6146 if (!eap->skip) 6147 if (!eap->skip)
6148 {
6149 if (rettv.v_type == VAR_VOID)
6150 {
6151 semsg(_(e_expression_does_not_result_in_value_str), arg_start);
6152 break;
6153 }
6147 echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr); 6154 echo_one(&rettv, eap->cmdidx == CMD_echo, &atstart, &needclr);
6155 }
6148 6156
6149 clear_tv(&rettv); 6157 clear_tv(&rettv);
6150 arg = skipwhite(arg); 6158 arg = skipwhite(arg);
6151 } 6159 }
6152 eap->nextcmd = check_nextcmd(arg); 6160 eap->nextcmd = check_nextcmd(arg);
6216 6224
6217 if (eap->cmdidx == CMD_execute) 6225 if (eap->cmdidx == CMD_execute)
6218 { 6226 {
6219 if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB) 6227 if (rettv.v_type == VAR_CHANNEL || rettv.v_type == VAR_JOB)
6220 { 6228 {
6221 emsg(_(e_inval_string)); 6229 semsg(_(e_using_invalid_value_as_string_str),
6230 vartype_name(rettv.v_type));
6222 p = NULL; 6231 p = NULL;
6223 } 6232 }
6224 else 6233 else
6225 p = tv_get_string_buf(&rettv, buf); 6234 p = tv_get_string_buf(&rettv, buf);
6226 } 6235 }