diff src/evalvars.c @ 20953:6b4b887a12f0 v8.2.1028

patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable Commit: https://github.com/vim/vim/commit/e55b1c098d9dc04c960e6575bb554b5130af8989 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 21 15:52:59 2020 +0200 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable Problem: Vim9: no error for declaring buffer, window, etc. variable. Solution: Give an error. Unify the error messages.
author Bram Moolenaar <Bram@vim.org>
date Sun, 21 Jun 2020 16:00:04 +0200
parents 0653b9b72091
children 7ee565134d4a
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -1204,6 +1204,13 @@ ex_let_one(
 	    emsg(_("E996: Cannot lock an environment variable"));
 	    return NULL;
 	}
+	if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
+		&& (flags & LET_NO_COMMAND) == 0)
+	{
+	    vim9_declare_error(arg);
+	    return NULL;
+	}
+
 	// Find the end of the name.
 	++arg;
 	name = arg;
@@ -2864,16 +2871,17 @@ set_var_const(
 	semsg(_(e_illvar), name);
 	return;
     }
+    is_script_local = ht == get_script_local_ht();
+
     if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
-	    && ht == &globvarht
-	    && (flags & LET_NO_COMMAND) == 0)
+	    && !is_script_local
+	    && (flags & LET_NO_COMMAND) == 0
+	    && name[1] == ':')
     {
-	semsg(_(e_declare_global), name);
+	vim9_declare_error(name);
 	return;
     }
 
-    is_script_local = ht == get_script_local_ht();
-
     di = find_var_in_ht(ht, 0, varname, TRUE);
 
     // Search in parent scope which is possible to reference from lambda