diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-13 19:00:10 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-13 19:00:10 +0200 |
commit | 34db91f7a47b7bd4aabf1e1dfbaa8a08278bf78d (patch) | |
tree | 116cb78d7fe2603f6213f355ad35c7ccbd3ebcd6 /src/vim9script.c | |
parent | c82a5b5da5eab15bc35115545b639fb590272ad7 (diff) | |
download | vim-git-34db91f7a47b7bd4aabf1e1dfbaa8a08278bf78d.tar.gz |
patch 8.2.0973: Vim9: type is not checked when assigning to a script variablev8.2.0973
Problem: Vim9: type is not checked when assigning to a script variable.
Solution: Check the type.
Diffstat (limited to 'src/vim9script.c')
-rw-r--r-- | src/vim9script.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vim9script.c b/src/vim9script.c index 51afa19a3..13a29ec3a 100644 --- a/src/vim9script.c +++ b/src/vim9script.c @@ -488,5 +488,30 @@ vim9_declare_scriptvar(exarg_T *eap, char_u *arg) return p; } +/* + * Check if the type of script variable "dest" allows assigning "value". + */ + void +check_script_var_type(typval_T *dest, typval_T *value, char_u *name) +{ + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); + int idx; + + // Find the svar_T in sn_var_vals. + for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx) + { + svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx; + + if (sv->sv_tv == dest) + { + if (sv->sv_const) + semsg(_(e_readonlyvar), name); + else + check_type(sv->sv_type, typval2type(value), TRUE); + return; + } + } + iemsg("check_script_var_type(): not found"); +} #endif // FEAT_EVAL |