patch 9.2.0627: :vim9cmd source handles all scripts as Vim9 script

Commit: 
https://github.com/vim/vim/commit/d696d4145888d2560ab0a3607b5822a15ddb4869
Author: Doug Kearns <[email protected]>
Date:   Sat Jun 13 15:29:42 2026 +0000

    patch 9.2.0627: :vim9cmd source handles all scripts as Vim9 script
    
    Problem:  Vim9: Commands modified by :vim9cmd source all scripts as Vim9
              script.
    Solution: Only source buffer lines as Vim9 via the :vim9cmd modifier.
              When sourcing a file, respect its script type.
    
    This caused `:vim9cmd gui` to launch the GUI without menus as the legacy
    script menus.vim file failed to load when sourced as Vim9 script.
    
    closes: #20452
    
    Signed-off-by: Doug Kearns <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/scriptfile.c b/src/scriptfile.c
index d0735ffe4..a9b257493 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1806,9 +1806,9 @@ do_source_ext(
     sticky_cmdmod_flags = 0;
 
     save_current_sctx = current_sctx;
-    if (cmdmod.cmod_flags & CMOD_VIM9CMD)
-       // When the ":vim9cmd" command modifier is used, source the script as a
-       // Vim9 script.
+    if ((cmdmod.cmod_flags & CMOD_VIM9CMD) && cookie.source_from_buf)
+       // When the ":vim9cmd" command modifier is used, source buffer lines as
+       // Vim9 script
        current_sctx.sc_version = SCRIPT_VERSION_VIM9;
     else
        current_sctx.sc_version = 1;  // default script version
diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim
index 1098e00ff..83c43b117 100644
--- a/src/testdir/test_gui.vim
+++ b/src/testdir/test_gui.vim
@@ -154,6 +154,24 @@ func Test_quoteplus()
   let @+ = quoteplus_saved
 endfunc
 
+" Test that legacy script menu files are sourced when :gui is executed with
+" the :vim9cmd modifier
+func Test_vim9cmd_gui()
+  CheckX11BasedGui
+
+  let lines =<< trim END
+    " Ignore the "failed to create input context" error.
+    call test_ignore_error("E285")
+    vim9cmd gui -f
+    call writefile([!empty(menu_info("Help"))], "XguimenuOK")
+    qa!
+  END
+  call writefile(lines, 'Xguimenuscript', 'D')
+  call system(GetVimCommand() .. ' --noplugin -S Xguimenuscript')
+  call assert_equal(['1'], readfile('XguimenuOK'))
+  call delete('XguimenuOK')
+endfunc
+
 func Test_gui_read_stdin()
   CheckUnix
 
diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim
index b7b0d1175..7982f51f0 100644
--- a/src/testdir/test_source.vim
+++ b/src/testdir/test_source.vim
@@ -635,6 +635,22 @@ func Test_source_buffer_vim9()
   %bw!
 endfunc
 
+" Test that the modifier does not override the script type when sourcing files
+" with :vim9cmd and :legacy
+func Test_source_file_ignores_modifiers()
+  let lines = ["let g:legacy_sourced = 42"]
+  call writefile(lines, 'Xsourcelegacy', 'D')
+  vim9cmd source Xsourcelegacy
+  call assert_equal(42, g:legacy_sourced)
+  unlet g:legacy_sourced
+
+  let lines = ["vim9script", "g:vim9_sourced = 42"]
+  call writefile(lines, 'Xsourcevim9', 'D')
+  legacy source Xsourcevim9
+  call assert_equal(42, g:vim9_sourced)
+  unlet g:vim9_sourced
+endfunc
+
 func Test_source_buffer_long_line()
   " This was reading past the end of the line.
   new
diff --git a/src/version.c b/src/version.c
index 956304845..812d66fd2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    627,
 /**/
     626,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1wYQXf-00DDbC-Dq%40256bit.org.

Raspunde prin e-mail lui