To: vim_dev@googlegroups.com Subject: Patch 8.2.4500 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4500 Problem: Vim9: can declare a global variable on the command line. Solution: Disallow declaring a variable on the command line. (closes #9881) Files: src/errors.h, src/evalvars.c, src/testdir/test_vim9_assign.vim, src/testdir/test_vim9_script.vim, src/testdir/dumps/Test_vim9_reject_declaration.dump *** ../vim-8.2.4499/src/errors.h 2022-02-23 22:11:58.774087749 +0000 --- src/errors.h 2022-03-03 16:36:32.950784499 +0000 *************** *** 2780,2793 **** INIT(= N_("E1074: No white space allowed after dot")); EXTERN char e_namespace_not_supported_str[] INIT(= N_("E1075: Namespace not supported: %s")); ! #ifndef FEAT_FLOAT EXTERN char e_this_vim_is_not_compiled_with_float_support[] INIT(= N_("E1076: This Vim is not compiled with float support")); ! #endif EXTERN char e_missing_argument_type_for_str[] INIT(= N_("E1077: Missing argument type for %s")); // E1078 unused ! // E1079 unused EXTERN char e_invalid_assignment[] INIT(= N_("E1080: Invalid assignment")); EXTERN char e_cannot_unlet_str[] --- 2780,2794 ---- INIT(= N_("E1074: No white space allowed after dot")); EXTERN char e_namespace_not_supported_str[] INIT(= N_("E1075: Namespace not supported: %s")); ! # ifndef FEAT_FLOAT EXTERN char e_this_vim_is_not_compiled_with_float_support[] INIT(= N_("E1076: This Vim is not compiled with float support")); ! # endif EXTERN char e_missing_argument_type_for_str[] INIT(= N_("E1077: Missing argument type for %s")); // E1078 unused ! EXTERN char e_cannot_declare_variable_on_command_line[] ! INIT(= N_("E1079: Cannot declare a variable on the command line")); EXTERN char e_invalid_assignment[] INIT(= N_("E1080: Invalid assignment")); EXTERN char e_cannot_unlet_str[] *** ../vim-8.2.4499/src/evalvars.c 2022-03-02 19:49:34.321061243 +0000 --- src/evalvars.c 2022-03-03 17:03:43.779169084 +0000 *************** *** 759,764 **** --- 759,769 ---- semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var"); return; } + if (current_sctx.sc_sid == 0) + { + emsg(_(e_cannot_declare_variable_on_command_line)); + return; + } ex_let(eap); } *************** *** 3440,3446 **** if (in_vim9script() && is_export && SCRIPT_ID_VALID(current_sctx.sc_sid) && (si = SCRIPT_ITEM(current_sctx.sc_sid)) ! ->sn_autoload_prefix != NULL) { // In a vim9 autoload script an exported variable is put in the // global namespace with the autoload prefix. --- 3445,3451 ---- if (in_vim9script() && is_export && SCRIPT_ID_VALID(current_sctx.sc_sid) && (si = SCRIPT_ITEM(current_sctx.sc_sid)) ! ->sn_autoload_prefix != NULL) { // In a vim9 autoload script an exported variable is put in the // global namespace with the autoload prefix. *** ../vim-8.2.4499/src/testdir/test_vim9_assign.vim 2022-02-28 20:54:58.129239044 +0000 --- src/testdir/test_vim9_assign.vim 2022-03-03 16:52:47.670851778 +0000 *************** *** 2480,2502 **** delete('Xtestscript') enddef - func Test_declare_command_line() - CheckRunVimInTerminal - call Run_Test_declare_command_line() - endfunc - - def Run_Test_declare_command_line() - # On the command line the type is parsed but not used. - # To get rid of the script context have to run this in another Vim instance. - var buf = g:RunVimInTerminal('', {'rows': 6}) - term_sendkeys(buf, ":vim9 var abc: list> = [ [1, 2, 3], [4, 5, 6] ]\") - g:TermWait(buf) - term_sendkeys(buf, ":echo abc\") - g:TermWait(buf) - g:WaitForAssert(() => assert_match('\[\[1, 2, 3\], \[4, 5, 6\]\]', term_getline(buf, 6))) - g:StopVimInTerminal(buf) - enddef - def Test_using_s_var_in_function() var lines =<< trim END vim9script --- 2480,2485 ---- *** ../vim-8.2.4499/src/testdir/test_vim9_script.vim 2022-03-03 15:11:15.082646961 +0000 --- src/testdir/test_vim9_script.vim 2022-03-03 16:48:39.146153689 +0000 *************** *** 3326,3359 **** func Test_no_redraw_when_restoring_cpo() CheckScreendump CheckFeature timers ! let lines =<< trim END vim9script export def Func() enddef END ! call mkdir('Xdir/autoload', 'p') ! call writefile(lines, 'Xdir/autoload/script.vim') ! let lines =<< trim END vim9script set cpo+=M exe 'set rtp^=' .. getcwd() .. '/Xdir' au CmdlineEnter : ++once timer_start(0, (_) => script#Func()) setline(1, 'some text') END ! call writefile(lines, 'XTest_redraw_cpo') ! let buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6}) ! call term_sendkeys(buf, "V:") ! call VerifyScreenDump(buf, 'Test_vim9_no_redraw', {}) ! ! " clean up ! call term_sendkeys(buf, "\u") ! call g:StopVimInTerminal(buf) ! call delete('XTest_redraw_cpo') ! call delete('Xdir', 'rf') endfunc def Test_unset_any_variable() var lines =<< trim END --- 3326,3375 ---- func Test_no_redraw_when_restoring_cpo() CheckScreendump CheckFeature timers + call Run_test_no_redraw_when_restoring_cpo() + endfunc ! def Run_test_no_redraw_when_restoring_cpo() ! var lines =<< trim END vim9script export def Func() enddef END ! mkdir('Xdir/autoload', 'p') ! writefile(lines, 'Xdir/autoload/script.vim') ! lines =<< trim END vim9script set cpo+=M exe 'set rtp^=' .. getcwd() .. '/Xdir' au CmdlineEnter : ++once timer_start(0, (_) => script#Func()) setline(1, 'some text') END ! writefile(lines, 'XTest_redraw_cpo') ! var buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6}) ! term_sendkeys(buf, "V:") ! g:VerifyScreenDump(buf, 'Test_vim9_no_redraw', {}) ! ! # clean up ! term_sendkeys(buf, "\u") ! g:StopVimInTerminal(buf) ! delete('XTest_redraw_cpo') ! delete('Xdir', 'rf') ! enddef ! ! func Test_reject_declaration() ! CheckScreendump ! call Run_test_reject_declaration() endfunc + def Run_test_reject_declaration() + var buf = g:RunVimInTerminal('', {'rows': 6}) + term_sendkeys(buf, ":vim9cmd var x: number\") + g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration', {}) + + # clean up + g:StopVimInTerminal(buf) + enddef def Test_unset_any_variable() var lines =<< trim END *** ../vim-8.2.4499/src/testdir/dumps/Test_vim9_reject_declaration.dump 2022-03-03 17:05:02.659129579 +0000 --- src/testdir/dumps/Test_vim9_reject_declaration.dump 2022-03-03 16:48:49.314192776 +0000 *************** *** 0 **** --- 1,6 ---- + |~+0#4040ff13#ffffff0| @73 + |~| @73 + |~| @73 + |~| @73 + |E+0#ffffff16#e000002|1|0|7|9|:| |C|a|n@1|o|t| |d|e|c|l|a|r|e| |a| |v|a|r|i|a|b|l|e| |o|n| |t|h|e| |c|o|m@1|a|n|d| |l|i|n|e| +0#0000000#ffffff0@22 + |P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| |c|o|n|t|i|n|u|e> +0#0000000&@35 *** ../vim-8.2.4499/src/version.c 2022-03-03 15:11:15.086646945 +0000 --- src/version.c 2022-03-03 16:49:40.246373311 +0000 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 4500, /**/ -- Although the scythe isn't pre-eminent among the weapons of war, anyone who has been on the wrong end of, say, a peasants' revolt will know that in skilled hands it is fearsome. -- (Terry Pratchett, Mort) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///