Mercurial > vim
comparison src/vim9script.c @ 25186:0a3b1c66d3f2 v8.2.3129
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Commit: https://github.com/vim/vim/commit/c967d57aa9a6bede0f50c6986dcddc1dc035a354
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 8 21:38:50 2021 +0200
patch 8.2.3129: Vim9: imported uninitialized list does not get type checked
Problem: Vim9: imported uninitialized list does not get type checked.
Solution: Get type from imported variable.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Jul 2021 21:45:04 +0200 |
parents | e495f40e4b07 |
children | 9bce044c7643 |
comparison
equal
deleted
inserted
replaced
25185:60ec756f39ab | 25186:0a3b1c66d3f2 |
---|---|
614 idx = find_exported(sid, name, &ufunc, &type, cctx, TRUE); | 614 idx = find_exported(sid, name, &ufunc, &type, cctx, TRUE); |
615 | 615 |
616 if (idx < 0 && ufunc == NULL) | 616 if (idx < 0 && ufunc == NULL) |
617 goto erret; | 617 goto erret; |
618 | 618 |
619 // If already imported with the same propertis and the | 619 // If already imported with the same properties and the |
620 // IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create | 620 // IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create |
621 // a new one (and give an error for an existing import). | 621 // a new one (and give an error for an existing import). |
622 imported = find_imported(name, len, cctx); | 622 imported = find_imported(name, len, cctx); |
623 if (imported != NULL | 623 if (imported != NULL |
624 && (imported->imp_flags & IMP_FLAGS_RELOAD) | 624 && (imported->imp_flags & IMP_FLAGS_RELOAD) |
804 // new variable name | 804 // new variable name |
805 hash_add(&si->sn_all_vars.dv_hashtab, newsav->sav_key); | 805 hash_add(&si->sn_all_vars.dv_hashtab, newsav->sav_key); |
806 } | 806 } |
807 else | 807 else |
808 { | 808 { |
809 sv = find_typval_in_script(&di->di_tv, TRUE); | 809 sv = find_typval_in_script(&di->di_tv); |
810 } | 810 } |
811 if (sv != NULL) | 811 if (sv != NULL) |
812 { | 812 { |
813 if (*type == NULL) | 813 if (*type == NULL) |
814 *type = typval2type(tv, get_copyID(), &si->sn_type_list, | 814 *type = typval2type(tv, get_copyID(), &si->sn_type_list, |
920 si->sn_script_seq = current_sctx.sc_seq; | 920 si->sn_script_seq = current_sctx.sc_seq; |
921 } | 921 } |
922 | 922 |
923 /* | 923 /* |
924 * Find the script-local variable that links to "dest". | 924 * Find the script-local variable that links to "dest". |
925 * Returns NULL if not found and when "give_error" is TRUE this is considered | 925 * Returns NULL if not found and give an internal error. |
926 * an internal error. | |
927 */ | 926 */ |
928 svar_T * | 927 svar_T * |
929 find_typval_in_script(typval_T *dest, int give_error) | 928 find_typval_in_script(typval_T *dest) |
930 { | 929 { |
931 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); | 930 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
932 int idx; | 931 int idx; |
933 | 932 |
934 if (si->sn_version != SCRIPT_VERSION_VIM9) | 933 if (si->sn_version != SCRIPT_VERSION_VIM9) |
943 // If "sv_name" is NULL the variable was hidden when leaving a block, | 942 // If "sv_name" is NULL the variable was hidden when leaving a block, |
944 // don't check "sv_tv" then, it might be used for another variable now. | 943 // don't check "sv_tv" then, it might be used for another variable now. |
945 if (sv->sv_name != NULL && sv->sv_tv == dest) | 944 if (sv->sv_name != NULL && sv->sv_tv == dest) |
946 return sv; | 945 return sv; |
947 } | 946 } |
948 if (give_error) | 947 iemsg("find_typval_in_script(): not found"); |
949 iemsg("find_typval_in_script(): not found"); | |
950 return NULL; | 948 return NULL; |
951 } | 949 } |
952 | 950 |
953 /* | 951 /* |
954 * Check if the type of script variable "dest" allows assigning "value". | 952 * Check if the type of script variable "dest" allows assigning "value". |
959 typval_T *dest, | 957 typval_T *dest, |
960 typval_T *value, | 958 typval_T *value, |
961 char_u *name, | 959 char_u *name, |
962 where_T where) | 960 where_T where) |
963 { | 961 { |
964 svar_T *sv = find_typval_in_script(dest, TRUE); | 962 svar_T *sv = find_typval_in_script(dest); |
965 int ret; | 963 int ret; |
966 | 964 |
967 if (sv != NULL) | 965 if (sv != NULL) |
968 { | 966 { |
969 if (sv->sv_const != 0) | 967 if (sv->sv_const != 0) |