Mercurial > vim
comparison src/eval.c @ 22529:35ef9b0a81a3 v8.2.1813
patch 8.2.1813: Vim9: can assign wrong type to script dict
Commit: https://github.com/vim/vim/commit/10c65860f83589e0ca2498393d3cfef1115b7fe8
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 8 21:16:42 2020 +0200
patch 8.2.1813: Vim9: can assign wrong type to script dict
Problem: Vim9: can assign wrong type to script dict. (Christian J. Robinson)
Solution: Check the type if known.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Oct 2020 21:30:03 +0200 |
parents | ef8a3177edc1 |
children | 7d6ba4204f66 |
comparison
equal
deleted
inserted
replaced
22528:61f656177bed | 22529:35ef9b0a81a3 |
---|---|
885 if (!quiet) | 885 if (!quiet) |
886 emsg(_("E708: [:] must come last")); | 886 emsg(_("E708: [:] must come last")); |
887 return NULL; | 887 return NULL; |
888 } | 888 } |
889 | 889 |
890 if (in_vim9script() && lp->ll_valtype == NULL | |
891 && lp->ll_tv == &v->di_tv | |
892 && ht != NULL && ht == get_script_local_ht()) | |
893 { | |
894 svar_T *sv = find_typval_in_script(lp->ll_tv); | |
895 | |
896 // Vim9 script local variable: get the type | |
897 if (sv != NULL) | |
898 lp->ll_valtype = sv->sv_type; | |
899 } | |
900 | |
890 len = -1; | 901 len = -1; |
891 if (*p == '.') | 902 if (*p == '.') |
892 { | 903 { |
893 key = p + 1; | 904 key = p + 1; |
894 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) | 905 for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len) |
1035 clear_tv(&var1); | 1046 clear_tv(&var1); |
1036 return NULL; | 1047 return NULL; |
1037 } | 1048 } |
1038 } | 1049 } |
1039 | 1050 |
1051 if (lp->ll_valtype != NULL) | |
1052 // use the type of the member | |
1053 lp->ll_valtype = lp->ll_valtype->tt_member; | |
1054 | |
1040 if (lp->ll_di == NULL) | 1055 if (lp->ll_di == NULL) |
1041 { | 1056 { |
1042 // Can't add "v:" or "a:" variable. | 1057 // Can't add "v:" or "a:" variable. |
1043 if (lp->ll_dict == get_vimvar_dict() | 1058 if (lp->ll_dict == get_vimvar_dict() |
1044 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) | 1059 || &lp->ll_dict->dv_hashtab == get_funccal_args_ht()) |
1145 clear_tv(&var2); | 1160 clear_tv(&var2); |
1146 if (!quiet) | 1161 if (!quiet) |
1147 semsg(_(e_listidx), lp->ll_n1); | 1162 semsg(_(e_listidx), lp->ll_n1); |
1148 return NULL; | 1163 return NULL; |
1149 } | 1164 } |
1165 | |
1166 if (lp->ll_valtype != NULL) | |
1167 // use the type of the member | |
1168 lp->ll_valtype = lp->ll_valtype->tt_member; | |
1150 | 1169 |
1151 /* | 1170 /* |
1152 * May need to find the item or absolute index for the second | 1171 * May need to find the item or absolute index for the second |
1153 * index of a range. | 1172 * index of a range. |
1154 * When no index given: "lp->ll_empty2" is TRUE. | 1173 * When no index given: "lp->ll_empty2" is TRUE. |
1381 if (flags & ASSIGN_CONST) | 1400 if (flags & ASSIGN_CONST) |
1382 { | 1401 { |
1383 emsg(_("E996: Cannot lock a list or dict")); | 1402 emsg(_("E996: Cannot lock a list or dict")); |
1384 return; | 1403 return; |
1385 } | 1404 } |
1405 | |
1406 if (lp->ll_valtype != NULL | |
1407 && check_typval_type(lp->ll_valtype, rettv, 0) == FAIL) | |
1408 return; | |
1409 | |
1386 if (lp->ll_newkey != NULL) | 1410 if (lp->ll_newkey != NULL) |
1387 { | 1411 { |
1388 if (op != NULL && *op != '=') | 1412 if (op != NULL && *op != '=') |
1389 { | 1413 { |
1390 semsg(_(e_letwrong), op); | 1414 semsg(_(e_letwrong), op); |