Mercurial > vim
comparison src/vim9script.c @ 23578:85ce241ff9e3 v8.2.2331
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Commit: https://github.com/vim/vim/commit/082517570d1dce2faf3baa9f752ce0858355d221
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 11 21:20:18 2021 +0100
patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Problem: Vim9: wrong error when modifying dict declared with :final.
Solution: Do not check for writable variable when an index follows.
(closes #7657)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 11 Jan 2021 21:30:03 +0100 |
parents | d2b1269c2c68 |
children | 85cf06ddb2a8 |
comparison
equal
deleted
inserted
replaced
23577:4009d936dc88 | 23578:85ce241ff9e3 |
---|---|
255 svar_T *sv; | 255 svar_T *sv; |
256 scriptitem_T *script = SCRIPT_ITEM(sid); | 256 scriptitem_T *script = SCRIPT_ITEM(sid); |
257 | 257 |
258 // find name in "script" | 258 // find name in "script" |
259 // TODO: also find script-local user function | 259 // TODO: also find script-local user function |
260 idx = get_script_item_idx(sid, name, FALSE, cctx); | 260 idx = get_script_item_idx(sid, name, 0, cctx); |
261 if (idx >= 0) | 261 if (idx >= 0) |
262 { | 262 { |
263 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx; | 263 sv = ((svar_T *)script->sn_var_vals.ga_data) + idx; |
264 if (!sv->sv_export) | 264 if (!sv->sv_export) |
265 { | 265 { |
659 /* | 659 /* |
660 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name | 660 * Vim9 part of adding a script variable: add it to sn_all_vars (lookup by name |
661 * with a hashtable) and sn_var_vals (lookup by index). | 661 * with a hashtable) and sn_var_vals (lookup by index). |
662 * When "create" is TRUE this is a new variable, otherwise find and update an | 662 * When "create" is TRUE this is a new variable, otherwise find and update an |
663 * existing variable. | 663 * existing variable. |
664 * "flags" can have ASSIGN_FINAL or ASSIGN_CONST. | |
664 * When "*type" is NULL use "tv" for the type and update "*type". | 665 * When "*type" is NULL use "tv" for the type and update "*type". |
665 */ | 666 */ |
666 void | 667 void |
667 update_vim9_script_var(int create, dictitem_T *di, typval_T *tv, type_T **type) | 668 update_vim9_script_var( |
669 int create, | |
670 dictitem_T *di, | |
671 int flags, | |
672 typval_T *tv, | |
673 type_T **type) | |
668 { | 674 { |
669 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); | 675 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
670 hashitem_T *hi; | 676 hashitem_T *hi; |
671 svar_T *sv; | 677 svar_T *sv; |
672 | 678 |
684 sizeof(sallvar_T) + STRLEN(di->di_key)); | 690 sizeof(sallvar_T) + STRLEN(di->di_key)); |
685 if (newsav == NULL) | 691 if (newsav == NULL) |
686 return; | 692 return; |
687 | 693 |
688 sv->sv_tv = &di->di_tv; | 694 sv->sv_tv = &di->di_tv; |
689 sv->sv_const = (di->di_flags & DI_FLAGS_LOCK) ? ASSIGN_CONST : 0; | 695 sv->sv_const = (flags & ASSIGN_FINAL) ? ASSIGN_FINAL |
696 : (flags & ASSIGN_CONST) ? ASSIGN_CONST : 0; | |
690 sv->sv_export = is_export; | 697 sv->sv_export = is_export; |
691 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len; | 698 newsav->sav_var_vals_idx = si->sn_var_vals.ga_len; |
692 ++si->sn_var_vals.ga_len; | 699 ++si->sn_var_vals.ga_len; |
693 STRCPY(&newsav->sav_key, di->di_key); | 700 STRCPY(&newsav->sav_key, di->di_key); |
694 sv->sv_name = newsav->sav_key; | 701 sv->sv_name = newsav->sav_key; |
862 svar_T *sv = find_typval_in_script(dest); | 869 svar_T *sv = find_typval_in_script(dest); |
863 int ret; | 870 int ret; |
864 | 871 |
865 if (sv != NULL) | 872 if (sv != NULL) |
866 { | 873 { |
867 if (sv->sv_const) | 874 if (sv->sv_const != 0) |
868 { | 875 { |
869 semsg(_(e_readonlyvar), name); | 876 semsg(_(e_readonlyvar), name); |
870 return FAIL; | 877 return FAIL; |
871 } | 878 } |
872 ret = check_typval_type(sv->sv_type, value, 0); | 879 ret = check_typval_type(sv->sv_type, value, 0); |