diff src/vim9compile.c @ 25939:377a7686a52f v8.2.3503

patch 8.2.3503: Vim9: using g:pat:cmd is confusing Commit: https://github.com/vim/vim/commit/7b829268921e8fc1c63c34d245063c1c4e7d21af Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 13 15:04:34 2021 +0100 patch 8.2.3503: Vim9: using g:pat:cmd is confusing Problem: Vim9: using g:pat:cmd is confusing. Solution: Do not recognize g: as the :global command. Also for s:pat:repl. (closes #8982)
author Bram Moolenaar <Bram@vim.org>
date Wed, 13 Oct 2021 16:15:04 +0200
parents d9a0847550c6
children 965a4823e5ef
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -9473,6 +9473,26 @@ compile_cexpr(char_u *line, exarg_T *eap
 #endif
 
 /*
+ * Check if the separator for a :global or :substitute command is OK.
+ */
+    int
+check_global_and_subst(char_u *cmd, char_u *arg)
+{
+    if (arg == cmd + 1 && vim_strchr(":-.", *arg) != NULL)
+    {
+	semsg(_(e_separator_not_supported_str), arg);
+	return FAIL;
+    }
+    if (VIM_ISWHITE(cmd[1]))
+    {
+	semsg(_(e_no_white_space_allowed_before_separator_str), cmd);
+	return FAIL;
+    }
+    return OK;
+}
+
+
+/*
  * Add a function to the list of :def functions.
  * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet.
  */
@@ -10066,6 +10086,8 @@ compile_def_function(
 		    break;
 
 	    case CMD_substitute:
+		    if (check_global_and_subst(ea.cmd, p) == FAIL)
+			goto erret;
 		    if (cctx.ctx_skip == SKIP_YES)
 			line = (char_u *)"";
 		    else
@@ -10132,6 +10154,10 @@ compile_def_function(
 			line = compile_script(line, &cctx);
 		    break;
 
+	    case CMD_global:
+		    if (check_global_and_subst(ea.cmd, p) == FAIL)
+			goto erret;
+		    // FALLTHROUGH
 	    default:
 		    // Not recognized, execute with do_cmdline_cmd().
 		    ea.arg = p;