mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.4500: Vim9: can declare a global variable on the command line
Problem: Vim9: can declare a global variable on the command line. Solution: Disallow declaring a variable on the command line. (closes #9881)
This commit is contained in:
@@ -2780,14 +2780,15 @@ EXTERN char e_no_white_space_allowed_after_dot[]
|
|||||||
INIT(= N_("E1074: No white space allowed after dot"));
|
INIT(= N_("E1074: No white space allowed after dot"));
|
||||||
EXTERN char e_namespace_not_supported_str[]
|
EXTERN char e_namespace_not_supported_str[]
|
||||||
INIT(= N_("E1075: Namespace not supported: %s"));
|
INIT(= N_("E1075: Namespace not supported: %s"));
|
||||||
#ifndef FEAT_FLOAT
|
# ifndef FEAT_FLOAT
|
||||||
EXTERN char e_this_vim_is_not_compiled_with_float_support[]
|
EXTERN char e_this_vim_is_not_compiled_with_float_support[]
|
||||||
INIT(= N_("E1076: This Vim is not compiled with float support"));
|
INIT(= N_("E1076: This Vim is not compiled with float support"));
|
||||||
#endif
|
# endif
|
||||||
EXTERN char e_missing_argument_type_for_str[]
|
EXTERN char e_missing_argument_type_for_str[]
|
||||||
INIT(= N_("E1077: Missing argument type for %s"));
|
INIT(= N_("E1077: Missing argument type for %s"));
|
||||||
// E1078 unused
|
// E1078 unused
|
||||||
// E1079 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[]
|
EXTERN char e_invalid_assignment[]
|
||||||
INIT(= N_("E1080: Invalid assignment"));
|
INIT(= N_("E1080: Invalid assignment"));
|
||||||
EXTERN char e_cannot_unlet_str[]
|
EXTERN char e_cannot_unlet_str[]
|
||||||
|
@@ -759,6 +759,11 @@ ex_var(exarg_T *eap)
|
|||||||
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
|
semsg(_(e_str_cannot_be_used_in_legacy_vim_script), ":var");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (current_sctx.sc_sid == 0)
|
||||||
|
{
|
||||||
|
emsg(_(e_cannot_declare_variable_on_command_line));
|
||||||
|
return;
|
||||||
|
}
|
||||||
ex_let(eap);
|
ex_let(eap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
src/testdir/dumps/Test_vim9_reject_declaration.dump
Normal file
6
src/testdir/dumps/Test_vim9_reject_declaration.dump
Normal file
@@ -0,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
|
@@ -2480,23 +2480,6 @@ def Test_abort_after_error()
|
|||||||
delete('Xtestscript')
|
delete('Xtestscript')
|
||||||
enddef
|
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<list<number>> = [ [1, 2, 3], [4, 5, 6] ]\<CR>")
|
|
||||||
g:TermWait(buf)
|
|
||||||
term_sendkeys(buf, ":echo abc\<CR>")
|
|
||||||
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()
|
def Test_using_s_var_in_function()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -3326,34 +3326,50 @@ enddef
|
|||||||
func Test_no_redraw_when_restoring_cpo()
|
func Test_no_redraw_when_restoring_cpo()
|
||||||
CheckScreendump
|
CheckScreendump
|
||||||
CheckFeature timers
|
CheckFeature timers
|
||||||
|
call Run_test_no_redraw_when_restoring_cpo()
|
||||||
|
endfunc
|
||||||
|
|
||||||
let lines =<< trim END
|
def Run_test_no_redraw_when_restoring_cpo()
|
||||||
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
export def Func()
|
export def Func()
|
||||||
enddef
|
enddef
|
||||||
END
|
END
|
||||||
call mkdir('Xdir/autoload', 'p')
|
mkdir('Xdir/autoload', 'p')
|
||||||
call writefile(lines, 'Xdir/autoload/script.vim')
|
writefile(lines, 'Xdir/autoload/script.vim')
|
||||||
|
|
||||||
let lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
set cpo+=M
|
set cpo+=M
|
||||||
exe 'set rtp^=' .. getcwd() .. '/Xdir'
|
exe 'set rtp^=' .. getcwd() .. '/Xdir'
|
||||||
au CmdlineEnter : ++once timer_start(0, (_) => script#Func())
|
au CmdlineEnter : ++once timer_start(0, (_) => script#Func())
|
||||||
setline(1, 'some text')
|
setline(1, 'some text')
|
||||||
END
|
END
|
||||||
call writefile(lines, 'XTest_redraw_cpo')
|
writefile(lines, 'XTest_redraw_cpo')
|
||||||
let buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6})
|
var buf = g:RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6})
|
||||||
call term_sendkeys(buf, "V:")
|
term_sendkeys(buf, "V:")
|
||||||
call VerifyScreenDump(buf, 'Test_vim9_no_redraw', {})
|
g:VerifyScreenDump(buf, 'Test_vim9_no_redraw', {})
|
||||||
|
|
||||||
" clean up
|
# clean up
|
||||||
call term_sendkeys(buf, "\<Esc>u")
|
term_sendkeys(buf, "\<Esc>u")
|
||||||
call g:StopVimInTerminal(buf)
|
g:StopVimInTerminal(buf)
|
||||||
call delete('XTest_redraw_cpo')
|
delete('XTest_redraw_cpo')
|
||||||
call delete('Xdir', 'rf')
|
delete('Xdir', 'rf')
|
||||||
|
enddef
|
||||||
|
|
||||||
|
func Test_reject_declaration()
|
||||||
|
CheckScreendump
|
||||||
|
call Run_test_reject_declaration()
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
def Run_test_reject_declaration()
|
||||||
|
var buf = g:RunVimInTerminal('', {'rows': 6})
|
||||||
|
term_sendkeys(buf, ":vim9cmd var x: number\<CR>")
|
||||||
|
g:VerifyScreenDump(buf, 'Test_vim9_reject_declaration', {})
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
g:StopVimInTerminal(buf)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_unset_any_variable()
|
def Test_unset_any_variable()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4500,
|
||||||
/**/
|
/**/
|
||||||
4499,
|
4499,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user