summaryrefslogtreecommitdiffstats
path: root/src/vim9execute.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-18 17:23:14 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-18 17:23:14 +0100
commit3beaf9cd8efa3ba83e07187215004d140b89d529 (patch)
tree193f21162a9cb4dc605cd16b1e8ab639d1d60520 /src/vim9execute.c
parent6e562fcc07c71ad1437c89c3d3cc423efb691f0a (diff)
patch 8.2.2159: Vim9: when declaring a list it is not allocated yetv8.2.2159
Problem: Vim9: when declaring a list it is not allocated yet, causing a following extend() to fail. Solution: When fetching a variable value for a list or dict that is null allocate the list or dict, so it can be used. (closes #7491)
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r--src/vim9execute.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 351ea8b3b1..64b42cb05b 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -791,6 +791,26 @@ store_var(char_u *name, typval_T *tv)
restore_funccal();
}
+/*
+ * When the value of "sv" is a null list of dict, allocate it.
+ */
+ static void
+allocate_if_null(typval_T *tv)
+{
+ switch (tv->v_type)
+ {
+ case VAR_LIST:
+ if (tv->vval.v_list == NULL)
+ rettv_list_alloc(tv);
+ break;
+ case VAR_DICT:
+ if (tv->vval.v_dict == NULL)
+ rettv_dict_alloc(tv);
+ break;
+ default:
+ break;
+ }
+}
/*
* Execute a function by "name".
@@ -1289,6 +1309,7 @@ call_def_function(
sv = ((svar_T *)si->sn_var_vals.ga_data)
+ iptr->isn_arg.script.script_idx;
+ allocate_if_null(sv->sv_tv);
if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
goto failed;
copy_tv(sv->sv_tv, STACK_TV_BOT(0));