]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0768: legacy/vim9cmd modifiers are not exclusive v9.2.0768
authorIllia Bobyr <illia.bobyr@gmail.com>
Thu, 2 Jul 2026 18:51:04 +0000 (18:51 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 2 Jul 2026 18:51:04 +0000 (18:51 +0000)
Problem:  legacy/vim9cmd modifiers are not exclusive
Solution: when parsing command modifiers clear the other flag
          (Illia Bobyr)

When one of the ":legacy" or ":vim9cmd" prefixes is used, it sets a
flag.  As the rest of the code might check either of the flags, setting
both could produce confusing results.  It does not make a lot of sense
to use both prefixes in the same command.  But just in case it is used,
selecting the last prefix seems reasonable.

closes: #20682

Signed-off-by: Illia Bobyr <illia.bobyr@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/ex_docmd.c
src/testdir/test_vim9_cmd.vim
src/version.c

index e716613ec24e0a9cd428715bac4657d73cb8178e..55db2d8d4d5c88ba4cf05893edd123bd9b4c00a2 100644 (file)
@@ -3092,6 +3092,9 @@ parse_command_modifiers(
                                      _(e_legacy_must_be_followed_by_command);
                                return FAIL;
                            }
+                           // Make sure we do not have both legacy and Vim9
+                           // flags set at the same time.
+                           cmod->cmod_flags &= ~CMOD_VIM9CMD;
                            cmod->cmod_flags |= CMOD_LEGACY;
                            continue;
                        }
@@ -3177,6 +3180,9 @@ parse_command_modifiers(
                                      _(e_vim9cmd_must_be_followed_by_command);
                                return FAIL;
                            }
+                           // Make sure we do not have both legacy and Vim9
+                           // flags set at the same time.
+                           cmod->cmod_flags &= ~CMOD_LEGACY;
                            cmod->cmod_flags |= CMOD_VIM9CMD;
                            continue;
                        }
index 1f421e2a4c4783025da820196449e2bf79892baa..8eaa2a875a57fd24cc16e8f40a156cba4d57ac35 100644 (file)
@@ -134,6 +134,23 @@ def Test_legacy_vim9cmd_preserved_by_options()
   v9.CheckScriptSuccess(lines)
 enddef
 
+def Test_legacy_vim9cmd_exclusive()
+  # Make sure that only one of the "legacy" or "vim9cmd" prefixes is applied.
+
+  # Invalid as vim9syntax.
+  call assert_fails("legacy vim9cmd echo 'a' . 'b'", 'E15:')
+  call assert_fails("legacy vim9cmd legacy vim9cmd echo 'a' . 'b'", 'E15:')
+
+  # Invalid legacy syntax.
+  call assert_fails("vim9cmd legacy echo (x) => x", 'E121:')
+  call assert_fails("vim9cmd legacy vim9cmd legacy echo (x) => x", 'E121:')
+
+  # Validate legacy/vim9 syntax being used.
+  call assert_equal('ab', trim(execute("vim9cmd legacy echo 'a' . 'b'")))
+  call assert_equal('true',
+    execute('legacy vim9cmd echo type((x) => x) == v:t_func')->trim())
+enddef
+
 def Test_defcompile_fails()
   assert_fails('defcompile NotExists', 'E1061:')
   assert_fails('defcompile debug debug Test_defcompile_fails', 'E488:')
index da6de93048431b5ce3e0168031369761d573df8c..d9a2c3310037e1280dbbd418a149df1e924fe654 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    768,
 /**/
     767,
 /**/