summaryrefslogtreecommitdiff
path: root/src/vim9execute.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-28 15:22:35 +0100
committerBram Moolenaar <Bram@vim.org>2022-03-28 15:22:35 +0100
commit859cc21c6b60af07b549456b7d050a03b3e48bc9 (patch)
treef2b27da6d782dc353fa52f8055b900b78997c6c7 /src/vim9execute.c
parent471b3aed3e9c43d4dd53444ceb74f9a4f8a3874a (diff)
downloadvim-git-859cc21c6b60af07b549456b7d050a03b3e48bc9.tar.gz
patch 8.2.4642: Vim9: in :def function script var cannot be nullv8.2.4642
Problem: Vim9: in :def function script var cannot be null. Solution: Only initialize a script variable when not set to a null value. (closes #10034)
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r--src/vim9execute.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 0404eb412..a95a48806 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1336,20 +1336,22 @@ do_2string(typval_T *tv, int is_2string_any, int tolerant)
* When the value of "sv" is a null list of dict, allocate it.
*/
static void
-allocate_if_null(typval_T *tv)
+allocate_if_null(svar_T *sv)
{
+ typval_T *tv = sv->sv_tv;
+
switch (tv->v_type)
{
case VAR_LIST:
- if (tv->vval.v_list == NULL)
+ if (tv->vval.v_list == NULL && sv->sv_type != &t_list_empty)
(void)rettv_list_alloc(tv);
break;
case VAR_DICT:
- if (tv->vval.v_dict == NULL)
+ if (tv->vval.v_dict == NULL && sv->sv_type != &t_dict_empty)
(void)rettv_dict_alloc(tv);
break;
case VAR_BLOB:
- if (tv->vval.v_blob == NULL)
+ if (tv->vval.v_blob == NULL && sv->sv_type != &t_blob_null)
(void)rettv_blob_alloc(tv);
break;
default:
@@ -2891,7 +2893,7 @@ exec_instructions(ectx_T *ectx)
sv = get_script_svar(sref, ectx->ec_dfunc_idx);
if (sv == NULL)
goto theend;
- allocate_if_null(sv->sv_tv);
+ allocate_if_null(sv);
if (GA_GROW_FAILS(&ectx->ec_stack, 1))
goto theend;
copy_tv(sv->sv_tv, STACK_TV_BOT(0));