comparison src/evalvars.c @ 28313:b418e073b42f v8.2.4682

patch 8.2.4682: Vim9: can use :unlockvar for const variable Commit: https://github.com/vim/vim/commit/7a411a306f90339d8686e42ac16e1ae4fc7533c5 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 4 14:58:06 2022 +0100 patch 8.2.4682: Vim9: can use :unlockvar for const variable Problem: Vim9: can use :unlockvar for const variable. (Ernie Rael) Solution: Check whether the variable is a const.
author Bram Moolenaar <Bram@vim.org>
date Mon, 04 Apr 2022 16:00:03 +0200
parents fff70771d4bb
children fabe722b24e9
comparison
equal deleted inserted replaced
28312:fb6d65010f23 28313:b418e073b42f
1949 if (in_vim9script()) 1949 if (in_vim9script())
1950 semsg(_(e_cannot_find_variable_to_unlock_str), 1950 semsg(_(e_cannot_find_variable_to_unlock_str),
1951 lp->ll_name); 1951 lp->ll_name);
1952 ret = FAIL; 1952 ret = FAIL;
1953 } 1953 }
1954 else if ((di->di_flags & DI_FLAGS_FIX) 1954 else
1955 {
1956 if ((di->di_flags & DI_FLAGS_FIX)
1955 && di->di_tv.v_type != VAR_DICT 1957 && di->di_tv.v_type != VAR_DICT
1956 && di->di_tv.v_type != VAR_LIST) 1958 && di->di_tv.v_type != VAR_LIST)
1957 { 1959 {
1958 // For historic reasons this error is not given for a list or 1960 // For historic reasons this error is not given for a list
1959 // dict. E.g., the b: dict could be locked/unlocked. 1961 // or dict. E.g., the b: dict could be locked/unlocked.
1960 semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name); 1962 semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name);
1961 ret = FAIL; 1963 ret = FAIL;
1962 } 1964 }
1963 else
1964 {
1965 if (lock)
1966 di->di_flags |= DI_FLAGS_LOCK;
1967 else 1965 else
1968 di->di_flags &= ~DI_FLAGS_LOCK; 1966 {
1969 if (deep != 0) 1967 if (in_vim9script())
1970 item_lock(&di->di_tv, deep, lock, FALSE); 1968 {
1969 svar_T *sv = find_typval_in_script(&di->di_tv,
1970 0, FALSE);
1971
1972 if (sv != NULL && sv->sv_const != 0)
1973 {
1974 semsg(_(e_cannot_change_readonly_variable_str),
1975 lp->ll_name);
1976 ret = FAIL;
1977 }
1978 }
1979
1980 if (ret == OK)
1981 {
1982 if (lock)
1983 di->di_flags |= DI_FLAGS_LOCK;
1984 else
1985 di->di_flags &= ~DI_FLAGS_LOCK;
1986 if (deep != 0)
1987 item_lock(&di->di_tv, deep, lock, FALSE);
1988 }
1989 }
1971 } 1990 }
1972 } 1991 }
1973 *name_end = cc; 1992 *name_end = cc;
1974 } 1993 }
1975 else if (deep == 0) 1994 else if (deep == 0)
2810 else if (rettv != NULL) 2829 else if (rettv != NULL)
2811 { 2830 {
2812 if (ht != NULL && ht == get_script_local_ht() 2831 if (ht != NULL && ht == get_script_local_ht()
2813 && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv) 2832 && tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv)
2814 { 2833 {
2815 svar_T *sv = find_typval_in_script(tv, 0); 2834 svar_T *sv = find_typval_in_script(tv, 0, TRUE);
2816 2835
2817 if (sv != NULL) 2836 if (sv != NULL)
2818 type = sv->sv_type; 2837 type = sv->sv_type;
2819 } 2838 }
2820 2839
3555 } 3574 }
3556 3575
3557 if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0) 3576 if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0)
3558 { 3577 {
3559 where_T where = WHERE_INIT; 3578 where_T where = WHERE_INIT;
3560 svar_T *sv = find_typval_in_script(&di->di_tv, sid); 3579 svar_T *sv = find_typval_in_script(&di->di_tv, sid, TRUE);
3561 3580
3562 if (sv != NULL) 3581 if (sv != NULL)
3563 { 3582 {
3564 // check the type and adjust to bool if needed 3583 // check the type and adjust to bool if needed
3565 where.wt_index = var_idx; 3584 where.wt_index = var_idx;