From: Illia Bobyr Date: Thu, 2 Jul 2026 18:51:04 +0000 (+0000) Subject: patch 9.2.0768: legacy/vim9cmd modifiers are not exclusive X-Git-Tag: v9.2.0768^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a9b46d323b16673d6b26360ef7907afb1b19cd0f;p=thirdparty%2Fvim.git patch 9.2.0768: legacy/vim9cmd modifiers are not exclusive 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 Signed-off-by: Christian Brabandt --- diff --git a/src/ex_docmd.c b/src/ex_docmd.c index e716613ec2..55db2d8d4d 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -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; } diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim index 1f421e2a4c..8eaa2a875a 100644 --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -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:') diff --git a/src/version.c b/src/version.c index da6de93048..d9a2c33100 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 768, /**/ 767, /**/