comparison src/vim9execute.c @ 23227:ccbbbbed371f v8.2.2159

patch 8.2.2159: Vim9: when declaring a list it is not allocated yet Commit: https://github.com/vim/vim/commit/3beaf9cd8efa3ba83e07187215004d140b89d529 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 18 17:23:14 2020 +0100 patch 8.2.2159: Vim9: when declaring a list it is not allocated yet 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 18 Dec 2020 17:30:04 +0100
parents cc24ac009f29
children b545334ae654
comparison
equal deleted inserted replaced
23226:e915f61040ec 23227:ccbbbbed371f
789 save_funccal(&entry); 789 save_funccal(&entry);
790 set_var_const(name, NULL, tv, FALSE, ASSIGN_NO_DECL); 790 set_var_const(name, NULL, tv, FALSE, ASSIGN_NO_DECL);
791 restore_funccal(); 791 restore_funccal();
792 } 792 }
793 793
794 /*
795 * When the value of "sv" is a null list of dict, allocate it.
796 */
797 static void
798 allocate_if_null(typval_T *tv)
799 {
800 switch (tv->v_type)
801 {
802 case VAR_LIST:
803 if (tv->vval.v_list == NULL)
804 rettv_list_alloc(tv);
805 break;
806 case VAR_DICT:
807 if (tv->vval.v_dict == NULL)
808 rettv_dict_alloc(tv);
809 break;
810 default:
811 break;
812 }
813 }
794 814
795 /* 815 /*
796 * Execute a function by "name". 816 * Execute a function by "name".
797 * This can be a builtin function, user function or a funcref. 817 * This can be a builtin function, user function or a funcref.
798 * "iptr" can be used to replace the instruction with a more efficient one. 818 * "iptr" can be used to replace the instruction with a more efficient one.
1287 SCRIPT_ITEM(iptr->isn_arg.script.script_sid); 1307 SCRIPT_ITEM(iptr->isn_arg.script.script_sid);
1288 svar_T *sv; 1308 svar_T *sv;
1289 1309
1290 sv = ((svar_T *)si->sn_var_vals.ga_data) 1310 sv = ((svar_T *)si->sn_var_vals.ga_data)
1291 + iptr->isn_arg.script.script_idx; 1311 + iptr->isn_arg.script.script_idx;
1312 allocate_if_null(sv->sv_tv);
1292 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) 1313 if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
1293 goto failed; 1314 goto failed;
1294 copy_tv(sv->sv_tv, STACK_TV_BOT(0)); 1315 copy_tv(sv->sv_tv, STACK_TV_BOT(0));
1295 ++ectx.ec_stack.ga_len; 1316 ++ectx.ec_stack.ga_len;
1296 } 1317 }