diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-04-05 21:40:38 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-05 21:40:38 +0100 |
commit | aa7d0c233532fb9d8c2876ea8e978a82b12c377f (patch) | |
tree | e1a7043513071fae2a4cb0a749f50804a4330fdb /src/evalvars.c | |
parent | 0d1f55c044610f627b1617e4cfbf6e094ff60921 (diff) | |
download | vim-git-aa7d0c233532fb9d8c2876ea8e978a82b12c377f.tar.gz |
patch 8.2.4698: Vim9: script variable has no flag that it was setv8.2.4698
Problem: Vim9: script variable has no flag that it was set.
Solution: Add a flag that it was set, to avoid giving it a value when used.
(closes #10088)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index c1ec5b0ba..0ee4b08d5 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -2828,13 +2828,18 @@ eval_variable( } else if (rettv != NULL) { + svar_T *sv = NULL; + int was_assigned = FALSE; + if (ht != NULL && ht == get_script_local_ht() && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv) { - svar_T *sv = find_typval_in_script(tv, 0, TRUE); - + sv = find_typval_in_script(tv, 0, TRUE); if (sv != NULL) + { type = sv->sv_type; + was_assigned = sv->sv_flags & SVFLAG_ASSIGNED; + } } // If a list or dict variable wasn't initialized and has meaningful @@ -2843,7 +2848,7 @@ eval_variable( if (ht != &globvarht) { if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL - && ((type != NULL && type != &t_dict_empty) + && ((type != NULL && !was_assigned) || !in_vim9script())) { tv->vval.v_dict = dict_alloc(); @@ -2851,10 +2856,12 @@ eval_variable( { ++tv->vval.v_dict->dv_refcount; tv->vval.v_dict->dv_type = alloc_type(type); + if (sv != NULL) + sv->sv_flags |= SVFLAG_ASSIGNED; } } else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL - && ((type != NULL && type != &t_list_empty) + && ((type != NULL && !was_assigned) || !in_vim9script())) { tv->vval.v_list = list_alloc(); @@ -2862,15 +2869,21 @@ eval_variable( { ++tv->vval.v_list->lv_refcount; tv->vval.v_list->lv_type = alloc_type(type); + if (sv != NULL) + sv->sv_flags |= SVFLAG_ASSIGNED; } } else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL - && ((type != NULL && type != &t_blob_null) + && ((type != NULL && !was_assigned) || !in_vim9script())) { tv->vval.v_blob = blob_alloc(); if (tv->vval.v_blob != NULL) + { ++tv->vval.v_blob->bv_refcount; + if (sv != NULL) + sv->sv_flags |= SVFLAG_ASSIGNED; + } } } copy_tv(tv, rettv); @@ -3587,6 +3600,7 @@ set_var_const( goto failed; if (type == NULL) type = sv->sv_type; + sv->sv_flags |= SVFLAG_ASSIGNED; } } |