mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2944: Vim9: no error when using job or channel as a string
Problem: Vim9: no error when using job or channel as a string. Solution: Be more strict about conversion to string. (closes #8312)
This commit is contained in:
40
src/typval.c
40
src/typval.c
@@ -414,7 +414,7 @@ tv_get_string_strict(typval_T *varp)
|
||||
char_u *
|
||||
tv_get_string_buf(typval_T *varp, char_u *buf)
|
||||
{
|
||||
char_u *res = tv_get_string_buf_chk(varp, buf);
|
||||
char_u *res = tv_get_string_buf_chk(varp, buf);
|
||||
|
||||
return res != NULL ? res : (char_u *)"";
|
||||
}
|
||||
@@ -478,44 +478,22 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
|
||||
break;
|
||||
case VAR_JOB:
|
||||
#ifdef FEAT_JOB_CHANNEL
|
||||
if (in_vim9script())
|
||||
{
|
||||
job_T *job = varp->vval.v_job;
|
||||
char *status;
|
||||
|
||||
if (job == NULL)
|
||||
return (char_u *)"no process";
|
||||
status = job->jv_status == JOB_FAILED ? "fail"
|
||||
: job->jv_status >= JOB_ENDED ? "dead"
|
||||
: "run";
|
||||
# ifdef UNIX
|
||||
vim_snprintf((char *)buf, NUMBUFLEN,
|
||||
"process %ld %s", (long)job->jv_pid, status);
|
||||
# elif defined(MSWIN)
|
||||
vim_snprintf((char *)buf, NUMBUFLEN,
|
||||
"process %ld %s",
|
||||
(long)job->jv_proc_info.dwProcessId,
|
||||
status);
|
||||
# else
|
||||
// fall-back
|
||||
vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status);
|
||||
# endif
|
||||
return buf;
|
||||
semsg(_(e_using_invalid_value_as_string_str), "job");
|
||||
break;
|
||||
}
|
||||
return job_to_string_buf(varp, buf);
|
||||
#endif
|
||||
break;
|
||||
case VAR_CHANNEL:
|
||||
#ifdef FEAT_JOB_CHANNEL
|
||||
if (in_vim9script())
|
||||
{
|
||||
channel_T *channel = varp->vval.v_channel;
|
||||
char *status = channel_status(channel, -1);
|
||||
|
||||
if (channel == NULL)
|
||||
vim_snprintf((char *)buf, NUMBUFLEN, "channel %s", status);
|
||||
else
|
||||
vim_snprintf((char *)buf, NUMBUFLEN,
|
||||
"channel %d %s", channel->ch_id, status);
|
||||
return buf;
|
||||
semsg(_(e_using_invalid_value_as_string_str), "channel");
|
||||
break;
|
||||
}
|
||||
return channel_to_string_buf(varp, buf);
|
||||
#endif
|
||||
break;
|
||||
case VAR_UNKNOWN:
|
||||
|
Reference in New Issue
Block a user