Patch 8.2.4360
Problem: Vim9: allowing use of "s:" leads to inconsistencies.
Solution: Disallow using "s:" in Vim9 script at the script level.
Files: src/userfunc.c, src/proto/
userfunc.pro, src/errors.h,
src/vim9compile.c, src/eval.c, src/testdir/vim9.vim,
src/testdir/test_vim9_assign.vim,
src/testdir/test_vim9_builtin.vim, src/testdir/test_vim9_cmd.vim,
src/testdir/test_vim9_disassemble.vim,
src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_func.vim,
src/testdir/test_vim9_import.vim, src/testdir/test_vim9_script.vim
*** ../vim-8.2.4359/src/userfunc.c 2022-02-08 20:35:23.749959758 +0000
--- src/userfunc.c 2022-02-12 18:57:50.800309980 +0000
***************
*** 3010,3015 ****
--- 3010,3027 ----
}
/*
+ * Return TRUE when currently at the script level:
+ * - not in a function
+ * - not executing an autocommand
+ * Note that when an autocommand sources a script the result is FALSE;
+ */
+ int
+ at_script_level(void)
+ {
+ return current_funccal == NULL && autocmd_match == NULL;
+ }
+
+ /*
* Mark all functions of script "sid" as deleted.
*/
void
***************
*** 4205,4210 ****
--- 4217,4228 ----
}
else
{
+ if (vim9script && p[0] == 's' && p[1] == ':')
+ {
+ semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p);
+ return NULL;
+ }
+
name = save_function_name(&p, &is_global, eap->skip,
TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi);
paren = (vim_strchr(p, '(') != NULL);
*** ../vim-8.2.4359/src/proto/
userfunc.pro 2022-01-30 15:28:26.642295028 +0000
--- src/proto/
userfunc.pro 2022-02-12 18:53:35.068497929 +0000
***************
*** 24,29 ****
--- 24,30 ----
void save_funccal(funccal_entry_T *entry);
void restore_funccal(void);
funccall_T *get_current_funccal(void);
+ int at_script_level(void);
void delete_script_functions(int sid);
void free_all_functions(void);
int builtin_function(char_u *name, int len);
*** ../vim-8.2.4359/src/errors.h 2022-02-08 19:12:15.260593033 +0000
--- src/errors.h 2022-02-12 18:38:33.724901042 +0000
***************
*** 2828,2834 ****
INIT(= N_("E1099: Unknown error while executing %s"));
EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[]
INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s"));
! EXTERN char e_cannot_declare_script_variable_in_function[]
INIT(= N_("E1101: Cannot declare a script variable in a function: %s"));
EXTERN char e_lambda_function_not_found_str[]
INIT(= N_("E1102: Lambda function not found: %s"));
--- 2828,2834 ----
INIT(= N_("E1099: Unknown error while executing %s"));
EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[]
INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s"));
! EXTERN char e_cannot_declare_script_variable_in_function_str[]
INIT(= N_("E1101: Cannot declare a script variable in a function: %s"));
EXTERN char e_lambda_function_not_found_str[]
INIT(= N_("E1102: Lambda function not found: %s"));
***************
*** 3232,3235 ****
--- 3232,3237 ----
#ifdef FEAT_EVAL
EXTERN char e_function_name_must_start_with_capital_str[]
INIT(= N_("E1267: Function name must start with a capital: %s"));
+ EXTERN char e_cannot_use_s_colon_in_vim9_script_str[]
+ INIT(= N_("E1268: Cannot use s: in Vim9 script: %s"));
#endif
*** ../vim-8.2.4359/src/vim9compile.c 2022-02-08 21:17:18.881463910 +0000
--- src/vim9compile.c 2022-02-11 17:32:11.447596688 +0000
***************
*** 1394,1400 ****
if (is_decl)
{
if (script_namespace)
! semsg(_(e_cannot_declare_script_variable_in_function),
lhs->lhs_name);
else
semsg(_(e_variable_already_declared_in_script_str),
--- 1394,1400 ----
if (is_decl)
{
if (script_namespace)
! semsg(_(e_cannot_declare_script_variable_in_function_str),
lhs->lhs_name);
else
semsg(_(e_variable_already_declared_in_script_str),
*** ../vim-8.2.4359/src/eval.c 2022-02-11 20:33:11.942342190 +0000
--- src/eval.c 2022-02-12 18:54:44.840448154 +0000
***************
*** 878,883 ****
--- 878,891 ----
return lp->ll_name_end;
}
+ // Cannot use "s:var" at the Vim9 script level. "s: type" is OK.
+ if (in_vim9script() && at_script_level()
+ && name[0] == 's' && name[1] == ':' && !VIM_ISWHITE(name[2]))
+ {
+ semsg(_(e_cannot_use_s_colon_in_vim9_script_str), name);
+ return NULL;
+ }
+
// Find the end of the name.
p = find_name_end(name, &expr_start, &expr_end, fne_flags);
lp->ll_name_end = p;
***************
*** 3732,3737 ****
--- 3740,3751 ----
emsg(_(e_cannot_use_underscore_here));
ret = FAIL;
}
+ else if (evaluate && in_vim9script() && len > 2
+ && s[0] == 's' && s[1] == ':')
+ {
+ semsg(_(e_cannot_use_s_colon_in_vim9_script_str), s);
+ ret = FAIL;
+ }
else if ((in_vim9script() ? **arg : *skipwhite(*arg)) == '(')
{
// "name(..." recursive!
*** ../vim-8.2.4359/src/testdir/vim9.vim 2022-01-29 21:45:30.473921671 +0000
--- src/testdir/vim9.vim 2022-02-10 21:50:29.115796938 +0000
***************
*** 73,80 ****
export def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
var cwd = getcwd()
! var fname = 'XScriptFailure' .. s:sequence
! s:sequence += 1
writefile(lines, fname)
try
assert_fails('so ' .. fname, error, lines, lnum)
--- 73,80 ----
export def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
var cwd = getcwd()
! var fname = 'XScriptFailure' .. sequence
! sequence += 1
writefile(lines, fname)
try
assert_fails('so ' .. fname, error, lines, lnum)
***************
*** 86,93 ****
export def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
var cwd = getcwd()
! var fname = 'XScriptFailure' .. s:sequence
! s:sequence += 1
writefile(lines, fname)
try
assert_fails('so ' .. fname, errors, lines, lnum)
--- 86,93 ----
export def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
var cwd = getcwd()
! var fname = 'XScriptFailure' .. sequence
! sequence += 1
writefile(lines, fname)
try
assert_fails('so ' .. fname, errors, lines, lnum)
***************
*** 99,106 ****
export def CheckScriptSuccess(lines: list<string>)
var cwd = getcwd()
! var fname = 'XScriptSuccess' .. s:sequence
! s:sequence += 1
writefile(lines, fname)
try
exe 'so ' .. fname
--- 99,106 ----
export def CheckScriptSuccess(lines: list<string>)
var cwd = getcwd()
! var fname = 'XScriptSuccess' .. sequence
! sequence += 1
writefile(lines, fname)
try
exe 'so ' .. fname
*** ../vim-8.2.4359/src/testdir/test_vim9_assign.vim 2022-02-06 17:16:57.730598839 +0000
--- src/testdir/test_vim9_assign.vim 2022-02-12 19:13:03.147716448 +0000
***************
*** 6,11 ****
--- 6,12 ----
let s:appendToMe = 'xxx'
let s:addToMe = 111
+ let s:newVar = ''
let g:existing = 'yes'
let g:inc_counter = 1
let $SOME_ENV_VAR = 'some'
***************
*** 124,135 ****
END
v9.CheckScriptSuccess(lines)
! s:appendToMe ..= 'yyy'
! assert_equal('xxxyyy', s:appendToMe)
! s:addToMe += 222
! assert_equal(333, s:addToMe)
! s:newVar = 'new'
! assert_equal('new', s:newVar)
set ts=7
var ts: number = &ts
--- 125,136 ----
END
v9.CheckScriptSuccess(lines)
! appendToMe ..= 'yyy'
! assert_equal('xxxyyy', appendToMe)
! addToMe += 222
! assert_equal(333, addToMe)
! newVar = 'new'
! assert_equal('new', newVar)
set ts=7
var ts: number = &ts
***************
*** 1195,1201 ****
assert_equal(5678, nr)
enddef
! let scriptvar = 'init'
def Test_assignment_var_list()
var lines =<< trim END
--- 1196,1202 ----
assert_equal(5678, nr)
enddef
! let s:scriptvar = 'init'
def Test_assignment_var_list()
var lines =<< trim END
***************
*** 1243,1259 ****
END
v9.CheckDefAndScriptSuccess(lines)
! [g:globalvar, s:scriptvar, b:bufvar] = ['global', 'script', 'buf']
assert_equal('global', g:globalvar)
! assert_equal('script', s:scriptvar)
assert_equal('buf', b:bufvar)
lines =<< trim END
vim9script
! var s:scriptvar = 'init'
! [g:globalvar, s:scriptvar, w:winvar] = ['global', 'script', 'win']
assert_equal('global', g:globalvar)
! assert_equal('script', s:scriptvar)
assert_equal('win', w:winvar)
END
v9.CheckScriptSuccess(lines)
--- 1244,1260 ----
END
v9.CheckDefAndScriptSuccess(lines)
! [g:globalvar, scriptvar, b:bufvar] = ['global', 'script', 'buf']
assert_equal('global', g:globalvar)
! assert_equal('script', scriptvar)
assert_equal('buf', b:bufvar)
lines =<< trim END
vim9script
! var scriptvar = 'init'
! [g:globalvar, scriptvar, w:winvar] = ['global', 'script', 'win']
assert_equal('global', g:globalvar)
! assert_equal('script', scriptvar)
assert_equal('win', w:winvar)
END
v9.CheckScriptSuccess(lines)
***************
*** 1398,1404 ****
v9.CheckDefFailure(["var xnr = xnr + 1"], 'E1001:', 1)
v9.CheckScriptFailure(['vim9script', 'var xnr = xnr + 4'], 'E121:')
! v9.CheckScriptFailure(['vim9script', 'def Func()', 'var dummy = s:notfound', 'enddef', 'defcompile'], 'E1108:')
v9.CheckDefFailure(['var name: list<string> = [123]'], 'expected list<string> but got list<number>')
v9.CheckDefFailure(['var name: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
--- 1399,1405 ----
v9.CheckDefFailure(["var xnr = xnr + 1"], 'E1001:', 1)
v9.CheckScriptFailure(['vim9script', 'var xnr = xnr + 4'], 'E121:')
! v9.CheckScriptFailure(['vim9script', 'def Func()', 'var dummy = notfound', 'enddef', 'defcompile'], 'E1001:')
v9.CheckDefFailure(['var name: list<string> = [123]'], 'expected list<string> but got list<number>')
v9.CheckDefFailure(['var name: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
***************
*** 1719,1727 ****
g:var_uninit = name
name = 'text'
g:var_test = name
! # prefixing s: is optional
! s:name = 'prefixed'
! g:var_prefixed = s:name
const FOO: number = 123
assert_equal(123, FOO)
--- 1720,1728 ----
g:var_uninit = name
name = 'text'
g:var_test = name
! # prefixing s: is not allowed
! name = 'prefixed'
! g:var_prefixed = name
const FOO: number = 123
assert_equal(123, FOO)
***************
*** 1764,1772 ****
var xyz: string # comment
# type is inferred
! var s:dict = {['a']: 222}
def GetDictVal(key: any)
! g:dict_val = s:dict[key]
enddef
GetDictVal('a')
--- 1765,1773 ----
var xyz: string # comment
# type is inferred
! var dict = {['a']: 222}
def GetDictVal(key: any)
! g:dict_val = dict[key]
enddef
GetDictVal('a')
***************
*** 1879,1891 ****
enddef
def Test_script_local_in_legacy()
! # OK to define script-local later when prefixed with s:
var lines =<< trim END
def SetLater()
! s:legvar = 'two'
enddef
- defcompile
let s:legvar = 'one'
call SetLater()
call assert_equal('two', s:legvar)
END
--- 1880,1892 ----
enddef
def Test_script_local_in_legacy()
! # OK to define script-local later but before compiling
var lines =<< trim END
def SetLater()
! legvar = 'two'
enddef
let s:legvar = 'one'
+ defcompile
call SetLater()
call assert_equal('two', s:legvar)
END
***************
*** 1902,1908 ****
END
v9.CheckScriptSuccess(lines)
! # Not OK to leave out s: prefix when script-local defined later
lines =<< trim END
def SetLaterNoPrefix()
legvar = 'two'
--- 1903,1909 ----
END
v9.CheckScriptSuccess(lines)
! # Not OK to leave out s: prefix when script-local defined after compiling
lines =<< trim END
def SetLaterNoPrefix()
legvar = 'two'
***************
*** 1944,1958 ****
lines =<< trim END
vim9script
! var s:l: list<number>
! s:l = []
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
! var s:d: dict<number>
! s:d = {}
END
v9.CheckScriptSuccess(lines)
--- 1945,1959 ----
lines =<< trim END
vim9script
! var l: list<number>
! l = []
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
! var d: dict<number>
! d = {}
END
v9.CheckScriptSuccess(lines)
***************
*** 2124,2130 ****
'vim9script',
'var svar = 123',
'unlet s:svar',
! ], 'E1081:')
v9.CheckScriptFailure([
'vim9script',
'var svar = 123',
--- 2125,2131 ----
'vim9script',
'var svar = 123',
'unlet s:svar',
! ], 'E1268:')
v9.CheckScriptFailure([
'vim9script',
'var svar = 123',
***************
*** 2267,2280 ****
lines =<< trim END
vim9script
! var s:Len = (s: string): number => len(s) + 2
assert_equal(6, Len('asdf'))
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
! var s:len = (s: string): number => len(s) + 1
END
v9.CheckScriptFailure(lines, 'E704:')
enddef
--- 2268,2281 ----
lines =<< trim END
vim9script
! var Len = (s: string): number => len(s) + 2
assert_equal(6, Len('asdf'))
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
! var len = (s: string): number => len(s) + 1
END
v9.CheckScriptFailure(lines, 'E704:')
enddef
*** ../vim-8.2.4359/src/testdir/test_vim9_builtin.vim 2022-02-06 18:36:46.297746545 +0000
--- src/testdir/test_vim9_builtin.vim 2022-02-10 21:54:06.183486968 +0000
***************
*** 2001,2009 ****
v9.CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
assert_equal([1, 2, 3], insert([2, 3], 1))
! assert_equal([1, 2, 3], insert([2, 3], s:number_one))
assert_equal([1, 2, 3], insert([1, 2], 3, 2))
! assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
assert_equal(0z1234, insert(0z34, 0x12))
--- 2001,2009 ----
v9.CheckDefExecAndScriptFailure(lines, 'E1131:', 1)
assert_equal([1, 2, 3], insert([2, 3], 1))
! assert_equal([1, 2, 3], insert([2, 3], number_one))
assert_equal([1, 2, 3], insert([1, 2], 3, 2))
! assert_equal([1, 2, 3], insert([1, 2], 3, number_two))
assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
assert_equal(0z1234, insert(0z34, 0x12))
*** ../vim-8.2.4359/src/testdir/test_vim9_cmd.vim 2022-02-12 13:30:12.760432016 +0000
--- src/testdir/test_vim9_cmd.vim 2022-02-12 19:29:50.439011378 +0000
***************
*** 1718,1724 ****
lines =<< trim END
s:notexist:repl
END
! v9.CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :repl', 'E121: Undefined variable: s:notexist'], 1)
lines =<< trim END
s-pat-repl
--- 1718,1729 ----
lines =<< trim END
s:notexist:repl
END
! v9.CheckDefAndScriptFailure(lines, ['E488: Trailing characters: :repl', 'E1268:'], 1)
!
! lines =<< trim END
! notexist:repl
! END
! v9.CheckDefAndScriptFailure(lines, ['E476:', 'E492:'], 1)
lines =<< trim END
s-pat-repl
*** ../vim-8.2.4359/src/testdir/test_vim9_disassemble.vim 2022-02-04 21:58:53.437278804 +0000
--- src/testdir/test_vim9_disassemble.vim 2022-02-12 19:35:21.642756477 +0000
***************
*** 300,310 ****
vim9script
import autoload 'autoscript.vim'
! def s:AutoloadFunc()
&operatorfunc = autoscript.Opfunc
enddef
! var res = execute('disass s:AutoloadFunc')
assert_match('<SNR>\d*_AutoloadFunc.*' ..
'&operatorfunc = autoscript.Opfunc\_s*' ..
'0 AUTOLOAD autoscript#Opfunc\_s*' ..
--- 300,310 ----
vim9script
import autoload 'autoscript.vim'
! def AutoloadFunc()
&operatorfunc = autoscript.Opfunc
enddef
! var res = execute('disass AutoloadFunc')
assert_match('<SNR>\d*_AutoloadFunc.*' ..
'&operatorfunc = autoscript.Opfunc\_s*' ..
'0 AUTOLOAD autoscript#Opfunc\_s*' ..
*** ../vim-8.2.4359/src/testdir/test_vim9_expr.vim 2022-02-04 21:17:54.412950056 +0000
--- src/testdir/test_vim9_expr.vim 2022-02-12 19:45:23.509589356 +0000
***************
*** 2329,2335 ****
v9.CheckDefAndScriptSuccess(lines)
enddef
! def Test_expr8_funcref()
var lines =<< trim END
def RetNumber(): number
return 123
--- 2329,2335 ----
v9.CheckDefAndScriptSuccess(lines)
enddef
! def Test_expr8funcref()
var lines =<< trim END
def RetNumber(): number
return 123
***************
*** 2344,2350 ****
func g:GlobalFunc()
return 'global'
endfunc
! func s:ScriptFunc()
return 'script'
endfunc
def Test()
--- 2344,2350 ----
func g:GlobalFunc()
return 'global'
endfunc
! func ScriptFunc()
return 'script'
endfunc
def Test()
***************
*** 2353,2359 ****
Ref = g:GlobalFunc
assert_equal('global', Ref())
! Ref = s:ScriptFunc
assert_equal('script', Ref())
Ref = ScriptFunc
assert_equal('script', Ref())
--- 2353,2359 ----
Ref = g:GlobalFunc
assert_equal('global', Ref())
! Ref = ScriptFunc
assert_equal('script', Ref())
Ref = ScriptFunc
assert_equal('script', Ref())
***************
*** 3347,3353 ****
call v9.CheckDefAndScriptFailure(["var x = ¬exist"], 'E113:', 1)
call v9.CheckDefAndScriptFailure(["&grepprg = [343]"], ['E1012:', 'E730:'], 1)
! call v9.CheckDefExecAndScriptFailure(["echo s:doesnt_exist"], 'E121:', 1)
call v9.CheckDefExecAndScriptFailure(["echo g:doesnt_exist"], 'E121:', 1)
call v9.CheckDefAndScriptFailure(["echo a:somevar"], ['E1075:', 'E121:'], 1)
--- 3347,3353 ----
call v9.CheckDefAndScriptFailure(["var x = ¬exist"], 'E113:', 1)
call v9.CheckDefAndScriptFailure(["&grepprg = [343]"], ['E1012:', 'E730:'], 1)
! call v9.CheckDefExecAndScriptFailure(["echo s:doesnt_exist"], ['E121:', 'E1268:'], 1)
call v9.CheckDefExecAndScriptFailure(["echo g:doesnt_exist"], 'E121:', 1)
call v9.CheckDefAndScriptFailure(["echo a:somevar"], ['E1075:', 'E121:'], 1)
*** ../vim-8.2.4359/src/testdir/test_vim9_func.vim 2022-02-08 20:35:23.753959753 +0000
--- src/testdir/test_vim9_func.vim 2022-02-12 19:42:47.070032378 +0000
***************
*** 713,719 ****
lines =<< trim END
vim9script
! def s:_Func()
echo 'bad'
enddef
END
--- 713,719 ----
lines =<< trim END
vim9script
! def _Func()
echo 'bad'
enddef
END
***************
*** 930,936 ****
def g:Funcy()
echo 'funcy'
enddef
! s:Funcy()
END
v9.CheckScriptFailure(lines, 'E117:')
enddef
--- 930,936 ----
def g:Funcy()
echo 'funcy'
enddef
! Funcy()
END
v9.CheckScriptFailure(lines, 'E117:')
enddef
***************
*** 1441,1450 ****
def Test_use_script_func_name_with_prefix()
var lines =<< trim END
vim9script
! func s:Getit()
return 'it'
endfunc
! var Fn = s:Getit
assert_equal('it', Fn())
END
v9.CheckScriptSuccess(lines)
--- 1441,1450 ----
def Test_use_script_func_name_with_prefix()
var lines =<< trim END
vim9script
! func g:Getit()
return 'it'
endfunc
! var Fn = g:Getit
assert_equal('it', Fn())
END
v9.CheckScriptSuccess(lines)
***************
*** 2849,2855 ****
lines =<< trim END
vim9script
! def s:Func()
range(10)
->mapnew((_, _) => ({
key: range(10)->mapnew((_, _) => {
--- 2849,2855 ----
lines =<< trim END
vim9script
! def Func()
range(10)
->mapnew((_, _) => ({
key: range(10)->mapnew((_, _) => {
***************
*** 3168,3174 ****
vim9script
def s: list<string>
END
! v9.CheckScriptFailure(lines, 'E129:')
lines =<< trim END
vim9script
--- 3168,3174 ----
vim9script
def s: list<string>
END
! v9.CheckScriptFailure(lines, 'E1268:')
lines =<< trim END
vim9script
*** ../vim-8.2.4359/src/testdir/test_vim9_import.vim 2022-02-08 19:12:15.260593033 +0000
--- src/testdir/test_vim9_import.vim 2022-02-12 19:46:03.765487651 +0000
***************
*** 1124,1130 ****
lines =<< trim END
vim9script noclear
g:loadCount += 1
! var s:reloaded = 'init'
import './XExportReload' as exp
def Again(): string
--- 1124,1130 ----
lines =<< trim END
vim9script noclear
g:loadCount += 1
! var reloaded = 'init'
import './XExportReload' as exp
def Again(): string
***************
*** 1133,1145 ****
exp.TheFunc()
! if exists('s:loaded') | finish | endif
! var s:loaded = true
! var s:notReloaded = 'yes'
! s:reloaded = 'first'
def g:Values(): list<string>
! return [s:reloaded, s:notReloaded, Again(), Once(), exp.exported]
enddef
def Once(): string
--- 1133,1145 ----
exp.TheFunc()
! if exists('loaded') | finish | endif
! var loaded = true
! var notReloaded = 'yes'
! reloaded = 'first'
def g:Values(): list<string>
! return [reloaded, notReloaded, Again(), Once(), exp.exported]
enddef
def Once(): string
*** ../vim-8.2.4359/src/testdir/test_vim9_script.vim 2022-02-12 14:23:14.047444006 +0000
--- src/testdir/test_vim9_script.vim 2022-02-12 19:05:23.271952054 +0000
***************
*** 69,75 ****
'func CheckMe()',
' return 123',
'endfunc',
! 'assert_equal(123, s:CheckMe())',
])
# Check function in script namespace cannot be deleted
--- 69,78 ----
'func CheckMe()',
' return 123',
'endfunc',
! 'func DoTest()',
! ' call assert_equal(123, s:CheckMe())',
! 'endfunc',
! 'DoTest()',
])
# Check function in script namespace cannot be deleted
***************
*** 178,188 ****
v9.CheckDefFailure(['var Ref: string', 'var res = Ref()'], 'E1085:')
enddef
def Test_script_wrong_type()
var lines =<< trim END
vim9script
! var s:dict: dict<string>
! s:dict['a'] = ['x']
END
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got list<string>', 3)
enddef
--- 181,235 ----
v9.CheckDefFailure(['var Ref: string', 'var res = Ref()'], 'E1085:')
enddef
+ def Test_script_namespace()
+ # defining a function or variable with s: is not allowed
+ var lines =<< trim END
+ vim9script
+ def s:Function()
+ enddef
+ END
+ v9.CheckScriptFailure(lines, 'E1268:')
+
+ for decl in ['var', 'const', 'final']
+ lines =<< trim END
+ vim9script
+ var s:var = 'var'
+ END
+ v9.CheckScriptFailure([
+ 'vim9script',
+ decl .. ' s:var = "var"',
+ ], 'E1268:')
+ endfor
+
+ # Calling a function or using a variable with s: is not allowed at script
+ # level
+ lines =<< trim END
+ vim9script
+ def Function()
+ enddef
+ s:Function()
+ END
+ v9.CheckScriptFailure(lines, 'E1268:')
+ lines =<< trim END
+ vim9script
+ def Function()
+ enddef
+ call s:Function()
+ END
+ v9.CheckScriptFailure(lines, 'E1268:')
+ lines =<< trim END
+ vim9script
+ var var = 'var'
+ echo s:var
+ END
+ v9.CheckScriptFailure(lines, 'E1268:')
+ enddef
+
def Test_script_wrong_type()
var lines =<< trim END
vim9script
! var dict: dict<string>
! dict['a'] = ['x']
END
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got list<string>', 3)
enddef
*** ../vim-8.2.4359/src/version.c 2022-02-12 15:42:14.957142547 +0000
--- src/version.c 2022-02-12 19:49:31.137024736 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4360,
/**/
--
hundred-and-one symptoms of being an internet addict:
32. You don't know what sex three of your closest friends are, because they
have neutral nicknames and you never bothered to ask.
/// Bram Moolenaar -- Br...@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 ///