patch 8.2.2193: Vim9: can change constant in :def function
Problem: Vim9: can change constant in :def function.
Solution: Check if a variable is locked. (issue #7526)
diff --git a/src/evalvars.c b/src/evalvars.c
index 572e5d5..ec3f508 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3125,13 +3125,7 @@
goto failed;
}
- // Check in this order for backwards compatibility:
- // - Whether the variable is read-only
- // - Whether the variable value is locked
- // - Whether the variable is locked
- if (var_check_ro(di->di_flags, name, FALSE)
- || value_check_lock(di->di_tv.v_lock, name, FALSE)
- || var_check_lock(di->di_flags, name, FALSE))
+ if (var_check_permission(di, name) == FAIL)
goto failed;
}
else
@@ -3243,6 +3237,22 @@
}
/*
+ * Check in this order for backwards compatibility:
+ * - Whether the variable is read-only
+ * - Whether the variable value is locked
+ * - Whether the variable is locked
+ */
+ int
+var_check_permission(dictitem_T *di, char_u *name)
+{
+ if (var_check_ro(di->di_flags, name, FALSE)
+ || value_check_lock(di->di_tv.v_lock, name, FALSE)
+ || var_check_lock(di->di_flags, name, FALSE))
+ return FAIL;
+ return OK;
+}
+
+/*
* Return TRUE if di_flags "flags" indicates variable "name" is read-only.
* Also give an error message.
*/