0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.1024: Vim9: no error for using "let g:var = val"

Problem:    Vim9: no error for using "let g:var = val".
Solution:   Add an error.
This commit is contained in:
Bram Moolenaar
2020-06-20 22:50:47 +02:00
parent 0cb5bcf583
commit 6797966dfc
10 changed files with 33 additions and 13 deletions

View File

@@ -2864,6 +2864,14 @@ set_var_const(
semsg(_(e_illvar), name);
return;
}
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
&& ht == &globvarht
&& (flags & LET_NO_COMMAND) == 0)
{
semsg(_(e_declare_global), name);
return;
}
is_script_local = ht == get_script_local_ht();
di = find_var_in_ht(ht, 0, varname, TRUE);

View File

@@ -1788,6 +1788,7 @@ EXTERN char e_no_white_before[] INIT(= N_("E1068: No white space allowed before
EXTERN char e_lock_unlock[] INIT(= N_("E940: Cannot lock or unlock variable %s"));
EXTERN char e_const_req_value[] INIT(= N_("E1021: const requires a value"));
EXTERN char e_type_req[] INIT(= N_("E1022: type or initialization required"));
EXTERN char e_declare_global[] INIT(= N_("E1016: Cannot declare a global variable: %s"));
#endif
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
EXTERN char e_alloc_color[] INIT(= N_("E254: Cannot allocate color %s"));

View File

@@ -1873,7 +1873,7 @@ ex_scriptversion(exarg_T *eap UNUSED)
nr = getdigits(&eap->arg);
if (nr == 0 || *eap->arg != NUL)
emsg(_(e_invarg));
else if (nr > 4)
else if (nr > SCRIPT_VERSION_MAX)
semsg(_("E999: scriptversion not supported: %d"), nr);
else
{

View File

@@ -67,6 +67,8 @@ typedef struct terminal_S term_T;
typedef struct VimMenu vimmenu_T;
#endif
// maximum value for sc_version
#define SCRIPT_VERSION_MAX 4
// value for sc_version in a Vim9 script file
#define SCRIPT_VERSION_VIM9 999999

View File

@@ -1190,7 +1190,7 @@ def Test_vim9script_forward_func()
def FuncTwo(): string
return 'two'
enddef
let g:res_FuncOne: string = execute('disass FuncOne')
g:res_FuncOne = execute('disass FuncOne')
END
writefile(lines, 'Xdisassemble')
source Xdisassemble

View File

@@ -323,7 +323,7 @@ def Test_vim9script_call()
str->MyFunc()
assert_equal('barfoo', var)
let g:value = 'value'
g:value = 'value'
g:value->MyFunc()
assert_equal('value', var)

View File

@@ -1099,11 +1099,11 @@ def Test_if_const_expr()
g:glob = 2
if false
execute('let g:glob = 3')
execute('g:glob = 3')
endif
assert_equal(2, g:glob)
if true
execute('let g:glob = 3')
execute('g:glob = 3')
endif
assert_equal(3, g:glob)
@@ -1790,8 +1790,8 @@ def Test_vim9_comment_gui()
enddef
def Test_vim9_comment_not_compiled()
au TabEnter *.vim let g:entered = 1
au TabEnter *.x let g:entered = 2
au TabEnter *.vim g:entered = 1
au TabEnter *.x g:entered = 2
edit test.vim
doautocmd TabEnter #comment
@@ -1811,7 +1811,7 @@ def Test_vim9_comment_not_compiled()
CheckScriptSuccess([
'vim9script',
'let g:var = 123',
'g:var = 123',
'let w:var = 777',
'unlet g:var w:var # something',
])
@@ -1819,6 +1819,11 @@ def Test_vim9_comment_not_compiled()
CheckScriptFailure([
'vim9script',
'let g:var = 123',
], 'E1016:')
CheckScriptFailure([
'vim9script',
'g:var = 123',
'unlet g:var# comment1',
], 'E108:')
@@ -1889,11 +1894,11 @@ enddef
def Test_finish()
let lines =<< trim END
vim9script
let g:res = 'one'
g:res = 'one'
if v:false | finish | endif
let g:res = 'two'
g:res = 'two'
finish
let g:res = 'three'
g:res = 'three'
END
writefile(lines, 'Xfinished')
source Xfinished

View File

@@ -3325,6 +3325,9 @@ def_function(exarg_T *eap, char_u *name_arg)
if (eap->cmdidx == CMD_def)
set_function_type(fp);
else if (fp->uf_script_ctx.sc_version == SCRIPT_VERSION_VIM9)
// :func does not use Vim9 script syntax, even in a Vim9 script file
fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX;
goto ret_free;

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1024,
/**/
1023,
/**/

View File

@@ -4871,8 +4871,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
dest = dest_global;
if (is_decl)
{
semsg(_("E1016: Cannot declare a global variable: %s"),
name);
semsg(_(e_declare_global), name);
goto theend;
}
}