diff src/evalvars.c @ 23295:d9ae7dd3a0f2 v8.2.2193

patch 8.2.2193: Vim9: can change constant in :def function Commit: https://github.com/vim/vim/commit/3bdc90b7dfab314768a8f56454ea62929524f05c Author: Bram Moolenaar <Bram@vim.org> Date: Tue Dec 22 20:35:40 2020 +0100 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 https://github.com/vim/vim/issues/7526)
author Bram Moolenaar <Bram@vim.org>
date Tue, 22 Dec 2020 20:45:04 +0100
parents a789a688e37d
children 40f1d3f0c53e
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3125,13 +3125,7 @@ set_var_const(
 		    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 @@ 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
+ */
+    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.
  */