comparison src/evalvars.c @ 24279:e3dbf2e58c6a v8.2.2680

patch 8.2.2680: Vim9: problem defining a script variable from legacy function Commit: https://github.com/vim/vim/commit/e535db86e76db5e8fcd2fa8ad54050e171e8adc3 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 31 21:07:24 2021 +0200 patch 8.2.2680: Vim9: problem defining a script variable from legacy function Problem: Vim9: problem defining a script variable from legacy function. Solution: Check if the script is Vim9, not the current syntax. (closes #8032)
author Bram Moolenaar <Bram@vim.org>
date Wed, 31 Mar 2021 21:15:03 +0200
parents db5eaad456cc
children 243985ba92b5
comparison
equal deleted inserted replaced
24278:4ab4ef0c48b1 24279:e3dbf2e58c6a
3166 dictitem_T *di; 3166 dictitem_T *di;
3167 char_u *varname; 3167 char_u *varname;
3168 hashtab_T *ht; 3168 hashtab_T *ht;
3169 int is_script_local; 3169 int is_script_local;
3170 int vim9script = in_vim9script(); 3170 int vim9script = in_vim9script();
3171 int var_in_vim9script;
3171 3172
3172 ht = find_var_ht(name, &varname); 3173 ht = find_var_ht(name, &varname);
3173 if (ht == NULL || *varname == NUL) 3174 if (ht == NULL || *varname == NUL)
3174 { 3175 {
3175 semsg(_(e_illvar), name); 3176 semsg(_(e_illvar), name);
3184 && name[1] == ':') 3185 && name[1] == ':')
3185 { 3186 {
3186 vim9_declare_error(name); 3187 vim9_declare_error(name);
3187 goto failed; 3188 goto failed;
3188 } 3189 }
3190 var_in_vim9script = is_script_local && current_script_is_vim9();
3189 3191
3190 di = find_var_in_ht(ht, 0, varname, TRUE); 3192 di = find_var_in_ht(ht, 0, varname, TRUE);
3191 3193
3192 // Search in parent scope which is possible to reference from lambda 3194 // Search in parent scope which is possible to reference from lambda
3193 if (di == NULL) 3195 if (di == NULL)
3215 { 3217 {
3216 emsg(_(e_cannot_mod)); 3218 emsg(_(e_cannot_mod));
3217 goto failed; 3219 goto failed;
3218 } 3220 }
3219 3221
3220 if (is_script_local && vim9script) 3222 if (var_in_vim9script)
3221 { 3223 {
3222 where_T where; 3224 where_T where;
3223 3225
3224 if ((flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0) 3226 if ((flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0)
3225 { 3227 {
3242 // can only redefine once 3244 // can only redefine once
3243 di->di_flags &= ~DI_FLAGS_RELOAD; 3245 di->di_flags &= ~DI_FLAGS_RELOAD;
3244 3246
3245 // A Vim9 script-local variable is also present in sn_all_vars and 3247 // A Vim9 script-local variable is also present in sn_all_vars and
3246 // sn_var_vals. It may set "type" from "tv". 3248 // sn_var_vals. It may set "type" from "tv".
3247 if (is_script_local && vim9script) 3249 if (var_in_vim9script)
3248 update_vim9_script_var(FALSE, di, flags, tv, &type); 3250 update_vim9_script_var(FALSE, di, flags, tv, &type);
3249 } 3251 }
3250 3252
3251 // existing variable, need to clear the value 3253 // existing variable, need to clear the value
3252 3254
3306 semsg(_(e_redefining_script_item_str), name); 3308 semsg(_(e_redefining_script_item_str), name);
3307 goto failed; 3309 goto failed;
3308 } 3310 }
3309 3311
3310 // add a new variable 3312 // add a new variable
3311 if (vim9script && is_script_local && (flags & ASSIGN_NO_DECL)) 3313 if (var_in_vim9script && (flags & ASSIGN_NO_DECL))
3312 { 3314 {
3313 semsg(_(e_unknown_variable_str), name); 3315 semsg(_(e_unknown_variable_str), name);
3314 goto failed; 3316 goto failed;
3315 } 3317 }
3316 3318
3340 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) 3342 if (flags & (ASSIGN_CONST | ASSIGN_FINAL))
3341 di->di_flags |= DI_FLAGS_LOCK; 3343 di->di_flags |= DI_FLAGS_LOCK;
3342 3344
3343 // A Vim9 script-local variable is also added to sn_all_vars and 3345 // A Vim9 script-local variable is also added to sn_all_vars and
3344 // sn_var_vals. It may set "type" from "tv". 3346 // sn_var_vals. It may set "type" from "tv".
3345 if (is_script_local && vim9script) 3347 if (var_in_vim9script)
3346 update_vim9_script_var(TRUE, di, flags, tv, &type); 3348 update_vim9_script_var(TRUE, di, flags, tv, &type);
3347 } 3349 }
3348 3350
3349 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) 3351 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT)
3350 copy_tv(tv, &di->di_tv); 3352 copy_tv(tv, &di->di_tv);