Mercurial > vim
comparison src/evalvars.c @ 28345:fabe722b24e9 v8.2.4698
patch 8.2.4698: Vim9: script variable has no flag that it was set
Commit: https://github.com/vim/vim/commit/aa7d0c233532fb9d8c2876ea8e978a82b12c377f
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 5 21:40:38 2022 +0100
patch 8.2.4698: Vim9: script variable has no flag that it was set
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 Apr 2022 22:45:03 +0200 |
parents | b418e073b42f |
children | 4dcccb2673fe |
comparison
equal
deleted
inserted
replaced
28344:10a99c04ba1d | 28345:fabe722b24e9 |
---|---|
2826 semsg(_(e_undefined_variable_str), name); | 2826 semsg(_(e_undefined_variable_str), name); |
2827 ret = FAIL; | 2827 ret = FAIL; |
2828 } | 2828 } |
2829 else if (rettv != NULL) | 2829 else if (rettv != NULL) |
2830 { | 2830 { |
2831 svar_T *sv = NULL; | |
2832 int was_assigned = FALSE; | |
2833 | |
2831 if (ht != NULL && ht == get_script_local_ht() | 2834 if (ht != NULL && ht == get_script_local_ht() |
2832 && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv) | 2835 && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv) |
2833 { | 2836 { |
2834 svar_T *sv = find_typval_in_script(tv, 0, TRUE); | 2837 sv = find_typval_in_script(tv, 0, TRUE); |
2835 | |
2836 if (sv != NULL) | 2838 if (sv != NULL) |
2839 { | |
2837 type = sv->sv_type; | 2840 type = sv->sv_type; |
2841 was_assigned = sv->sv_flags & SVFLAG_ASSIGNED; | |
2842 } | |
2838 } | 2843 } |
2839 | 2844 |
2840 // If a list or dict variable wasn't initialized and has meaningful | 2845 // If a list or dict variable wasn't initialized and has meaningful |
2841 // type, do it now. Not for global variables, they are not | 2846 // type, do it now. Not for global variables, they are not |
2842 // declared. | 2847 // declared. |
2843 if (ht != &globvarht) | 2848 if (ht != &globvarht) |
2844 { | 2849 { |
2845 if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL | 2850 if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL |
2846 && ((type != NULL && type != &t_dict_empty) | 2851 && ((type != NULL && !was_assigned) |
2847 || !in_vim9script())) | 2852 || !in_vim9script())) |
2848 { | 2853 { |
2849 tv->vval.v_dict = dict_alloc(); | 2854 tv->vval.v_dict = dict_alloc(); |
2850 if (tv->vval.v_dict != NULL) | 2855 if (tv->vval.v_dict != NULL) |
2851 { | 2856 { |
2852 ++tv->vval.v_dict->dv_refcount; | 2857 ++tv->vval.v_dict->dv_refcount; |
2853 tv->vval.v_dict->dv_type = alloc_type(type); | 2858 tv->vval.v_dict->dv_type = alloc_type(type); |
2859 if (sv != NULL) | |
2860 sv->sv_flags |= SVFLAG_ASSIGNED; | |
2854 } | 2861 } |
2855 } | 2862 } |
2856 else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL | 2863 else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL |
2857 && ((type != NULL && type != &t_list_empty) | 2864 && ((type != NULL && !was_assigned) |
2858 || !in_vim9script())) | 2865 || !in_vim9script())) |
2859 { | 2866 { |
2860 tv->vval.v_list = list_alloc(); | 2867 tv->vval.v_list = list_alloc(); |
2861 if (tv->vval.v_list != NULL) | 2868 if (tv->vval.v_list != NULL) |
2862 { | 2869 { |
2863 ++tv->vval.v_list->lv_refcount; | 2870 ++tv->vval.v_list->lv_refcount; |
2864 tv->vval.v_list->lv_type = alloc_type(type); | 2871 tv->vval.v_list->lv_type = alloc_type(type); |
2872 if (sv != NULL) | |
2873 sv->sv_flags |= SVFLAG_ASSIGNED; | |
2865 } | 2874 } |
2866 } | 2875 } |
2867 else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL | 2876 else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL |
2868 && ((type != NULL && type != &t_blob_null) | 2877 && ((type != NULL && !was_assigned) |
2869 || !in_vim9script())) | 2878 || !in_vim9script())) |
2870 { | 2879 { |
2871 tv->vval.v_blob = blob_alloc(); | 2880 tv->vval.v_blob = blob_alloc(); |
2872 if (tv->vval.v_blob != NULL) | 2881 if (tv->vval.v_blob != NULL) |
2882 { | |
2873 ++tv->vval.v_blob->bv_refcount; | 2883 ++tv->vval.v_blob->bv_refcount; |
2884 if (sv != NULL) | |
2885 sv->sv_flags |= SVFLAG_ASSIGNED; | |
2886 } | |
2874 } | 2887 } |
2875 } | 2888 } |
2876 copy_tv(tv, rettv); | 2889 copy_tv(tv, rettv); |
2877 } | 2890 } |
2878 } | 2891 } |
3585 where.wt_variable = TRUE; | 3598 where.wt_variable = TRUE; |
3586 if (check_script_var_type(sv, tv, name, where) == FAIL) | 3599 if (check_script_var_type(sv, tv, name, where) == FAIL) |
3587 goto failed; | 3600 goto failed; |
3588 if (type == NULL) | 3601 if (type == NULL) |
3589 type = sv->sv_type; | 3602 type = sv->sv_type; |
3603 sv->sv_flags |= SVFLAG_ASSIGNED; | |
3590 } | 3604 } |
3591 } | 3605 } |
3592 | 3606 |
3593 if ((flags & ASSIGN_FOR_LOOP) == 0 | 3607 if ((flags & ASSIGN_FOR_LOOP) == 0 |
3594 && var_check_permission(di, name) == FAIL) | 3608 && var_check_permission(di, name) == FAIL) |