Mercurial > vim
comparison src/evalvars.c @ 24051:da8347e453b4 v8.2.2567
patch 8.2.2567: Vim9: no error if variable is defined for existing function
Commit: https://github.com/vim/vim/commit/6c3843ca8ab105bfb85f6ea8bcec2cbc03f46e7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 4 12:38:21 2021 +0100
patch 8.2.2567: Vim9: no error if variable is defined for existing function
Problem: Vim9: no error if variable is defined for existing function.
Solution: Check if name isn't already in use. (closes https://github.com/vim/vim/issues/7897)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Mar 2021 12:45:03 +0100 |
parents | fc4c2beea99a |
children | c5e396fb0ebe |
comparison
equal
deleted
inserted
replaced
24050:df5c5e5bda0c | 24051:da8347e453b4 |
---|---|
907 } | 907 } |
908 } | 908 } |
909 } | 909 } |
910 | 910 |
911 /* | 911 /* |
912 * Assign the typevalue "tv" to the variable or variables at "arg_start". | 912 * Assign the typeval "tv" to the variable or variables at "arg_start". |
913 * Handles both "var" with any type and "[var, var; var]" with a list type. | 913 * Handles both "var" with any type and "[var, var; var]" with a list type. |
914 * When "op" is not NULL it points to a string with characters that | 914 * When "op" is not NULL it points to a string with characters that |
915 * must appear after the variable(s). Use "+", "-" or "." for add, subtract | 915 * must appear after the variable(s). Use "+", "-" or "." for add, subtract |
916 * or concatenate. | 916 * or concatenate. |
917 * Returns OK or FAIL; | 917 * Returns OK or FAIL; |
3177 tv = &bool_tv; | 3177 tv = &bool_tv; |
3178 } | 3178 } |
3179 | 3179 |
3180 if (di != NULL) | 3180 if (di != NULL) |
3181 { | 3181 { |
3182 // Item already exists. Allowed to replace when reloading. | |
3182 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) | 3183 if ((di->di_flags & DI_FLAGS_RELOAD) == 0) |
3183 { | 3184 { |
3184 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) | 3185 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
3185 { | 3186 { |
3186 emsg(_(e_cannot_mod)); | 3187 emsg(_(e_cannot_mod)); |
3267 | 3268 |
3268 clear_tv(&di->di_tv); | 3269 clear_tv(&di->di_tv); |
3269 } | 3270 } |
3270 else | 3271 else |
3271 { | 3272 { |
3273 // Item not found, check if a function already exists. | |
3274 if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0 | |
3275 && lookup_scriptitem(name, STRLEN(name), NULL) == OK) | |
3276 { | |
3277 semsg(_(e_redefining_script_item_str), name); | |
3278 goto failed; | |
3279 } | |
3280 | |
3272 // add a new variable | 3281 // add a new variable |
3273 if (vim9script && is_script_local && (flags & ASSIGN_NO_DECL)) | 3282 if (vim9script && is_script_local && (flags & ASSIGN_NO_DECL)) |
3274 { | 3283 { |
3275 semsg(_(e_unknown_variable_str), name); | 3284 semsg(_(e_unknown_variable_str), name); |
3276 goto failed; | 3285 goto failed; |