diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-27 22:00:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-27 22:00:44 +0200 |
commit | 4490ec4e839e45a2e6923c265c7e9e64c240b805 (patch) | |
tree | 3ef2dc127890ac6a644f38ae7932b7e70071544a /src/channel.c | |
parent | 5d7c2df536c17db4a9c61e0760bdcf78d0db7330 (diff) | |
download | vim-git-4490ec4e839e45a2e6923c265c7e9e64c240b805.tar.gz |
patch 8.2.3229: Vim9: runtime and compile time type checks are not the samev8.2.3229
Problem: Vim9: runtime and compile time type checks are not the same.
Solution: Add more runtime type checks for builtin functions. (Yegappan
Lakshmanan, closes #8646)
Diffstat (limited to 'src/channel.c')
-rw-r--r-- | src/channel.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/channel.c b/src/channel.c index 46bdc0ec8..5307792e8 100644 --- a/src/channel.c +++ b/src/channel.c @@ -3865,6 +3865,11 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw, int blob) rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; + if (in_vim9script() + && (check_for_chan_or_job_arg(argvars, 0) == FAIL + || check_for_opt_dict_arg(argvars, 1) == FAIL)) + return; + clear_job_options(&opt); if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID, 0) == FAIL) @@ -4784,9 +4789,13 @@ channel_get_timeout(channel_T *channel, ch_part_T part) void f_ch_canread(typval_T *argvars, typval_T *rettv) { - channel_T *channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); + channel_T *channel; rettv->vval.v_number = 0; + if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) + return; + + channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); if (channel != NULL) rettv->vval.v_number = channel_has_readahead(channel, PART_SOCK) || channel_has_readahead(channel, PART_OUT) @@ -4799,8 +4808,12 @@ f_ch_canread(typval_T *argvars, typval_T *rettv) void f_ch_close(typval_T *argvars, typval_T *rettv UNUSED) { - channel_T *channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); + channel_T *channel; + if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) + return; + + channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); if (channel != NULL) { channel_close(channel, FALSE); @@ -4814,8 +4827,12 @@ f_ch_close(typval_T *argvars, typval_T *rettv UNUSED) void f_ch_close_in(typval_T *argvars, typval_T *rettv UNUSED) { - channel_T *channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); + channel_T *channel; + if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) + return; + + channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); if (channel != NULL) channel_close_in(channel); } @@ -4861,8 +4878,12 @@ f_ch_getbufnr(typval_T *argvars, typval_T *rettv) void f_ch_getjob(typval_T *argvars, typval_T *rettv) { - channel_T *channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); + channel_T *channel; + if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) + return; + + channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); if (channel != NULL) { rettv->v_type = VAR_JOB; @@ -4878,8 +4899,12 @@ f_ch_getjob(typval_T *argvars, typval_T *rettv) void f_ch_info(typval_T *argvars, typval_T *rettv UNUSED) { - channel_T *channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); + channel_T *channel; + if (in_vim9script() && check_for_chan_or_job_arg(argvars, 0) == FAIL) + return; + + channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); if (channel != NULL && rettv_dict_alloc(rettv) != FAIL) channel_info(channel, rettv->vval.v_dict); } @@ -4921,7 +4946,7 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED) if (in_vim9script() && (check_for_string_arg(argvars, 0) == FAIL - || check_for_string_arg(argvars, 1) == FAIL)) + || check_for_opt_string_arg(argvars, 1) == FAIL)) return; fname = tv_get_string(&argvars[0]); @@ -5014,6 +5039,11 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED) channel_T *channel; jobopt_T opt; + if (in_vim9script() + && (check_for_chan_or_job_arg(argvars, 0) == FAIL + || check_for_dict_arg(argvars, 1) == FAIL)) + return; + channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); if (channel == NULL) return; @@ -5038,6 +5068,11 @@ f_ch_status(typval_T *argvars, typval_T *rettv) rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; + if (in_vim9script() + && (check_for_chan_or_job_arg(argvars, 0) == FAIL + || check_for_opt_dict_arg(argvars, 1) == FAIL)) + return; + channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); if (argvars[1].v_type != VAR_UNKNOWN) |