Patch 8.2.1028

11 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 21, 2020, 9:53:37 AM6/21/20
to vim...@googlegroups.com

Patch 8.2.1028
Problem: Vim9: no error for declaring buffer, window, etc. variable.
Solution: Give an error. Unify the error messages.
Files: src/evalvars.c, src/globals.h, src/vim9compile.c,
src/proto/vim9compile.pro, src/testdir/test_vim9_expr.vim,
src/testdir/test_vim9_script.vim


*** ../vim-8.2.1027/src/evalvars.c 2020-06-20 22:50:44.171608245 +0200
--- src/evalvars.c 2020-06-21 15:50:21.598728537 +0200
***************
*** 1204,1209 ****
--- 1204,1216 ----
emsg(_("E996: Cannot lock an environment variable"));
return NULL;
}
+ if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
+ && (flags & LET_NO_COMMAND) == 0)
+ {
+ vim9_declare_error(arg);
+ return NULL;
+ }
+
// Find the end of the name.
++arg;
name = arg;
***************
*** 2864,2879 ****
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);

// Search in parent scope which is possible to reference from lambda
--- 2871,2887 ----
semsg(_(e_illvar), name);
return;
}
+ is_script_local = ht == get_script_local_ht();
+
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
! && !is_script_local
! && (flags & LET_NO_COMMAND) == 0
! && name[1] == ':')
{
! vim9_declare_error(name);
return;
}

di = find_var_in_ht(ht, 0, varname, TRUE);

// Search in parent scope which is possible to reference from lambda
*** ../vim-8.2.1027/src/globals.h 2020-06-20 22:50:44.171608245 +0200
--- src/globals.h 2020-06-21 15:42:22.731231050 +0200
***************
*** 1788,1794 ****
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"));
--- 1788,1794 ----
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_var[] INIT(= N_("E1016: Cannot declare a%s variable: %s"));
#endif
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
EXTERN char e_alloc_color[] INIT(= N_("E254: Cannot allocate color %s"));
*** ../vim-8.2.1027/src/vim9compile.c 2020-06-21 14:12:14.014668156 +0200
--- src/vim9compile.c 2020-06-21 15:42:15.039254482 +0200
***************
*** 4659,4664 ****
--- 4659,4681 ----
}
}

+ void
+ vim9_declare_error(char_u *name)
+ {
+ char *scope = "";
+
+ switch (*name)
+ {
+ case 'g': scope = " global"; break;
+ case 'b': scope = " buffer"; break;
+ case 'w': scope = " window"; break;
+ case 't': scope = " tab"; break;
+ case 'v': scope = " v:"; break;
+ case '$': scope = "n environment"; break;
+ }
+ semsg(_(e_declare_var), scope, name);
+ }
+
/*
* Compile declaration and assignment:
* "let var", "let var = expr", "const var = expr" and "var = expr"
***************
*** 4855,4862 ****
type = &t_string;
if (is_decl)
{
! semsg(_("E1065: Cannot declare an environment variable: %s"),
! name);
goto theend;
}
}
--- 4872,4878 ----
type = &t_string;
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
***************
*** 4880,4886 ****
dest = dest_global;
if (is_decl)
{
! semsg(_(e_declare_global), name);
goto theend;
}
}
--- 4896,4902 ----
dest = dest_global;
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
***************
*** 4889,4896 ****
dest = dest_buffer;
if (is_decl)
{
! semsg(_("E1078: Cannot declare a buffer variable: %s"),
! name);
goto theend;
}
}
--- 4905,4911 ----
dest = dest_buffer;
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
***************
*** 4899,4906 ****
dest = dest_window;
if (is_decl)
{
! semsg(_("E1079: Cannot declare a window variable: %s"),
! name);
goto theend;
}
}
--- 4914,4920 ----
dest = dest_window;
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
***************
*** 4909,4915 ****
dest = dest_tab;
if (is_decl)
{
! semsg(_("E1080: Cannot declare a tab variable: %s"), name);
goto theend;
}
}
--- 4923,4929 ----
dest = dest_tab;
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
***************
*** 4932,4938 ****
type = typval2type(vtv);
if (is_decl)
{
! semsg(_("E1064: Cannot declare a v: variable: %s"), name);
goto theend;
}
}
--- 4946,4952 ----
type = typval2type(vtv);
if (is_decl)
{
! vim9_declare_error(name);
goto theend;
}
}
*** ../vim-8.2.1027/src/proto/vim9compile.pro 2020-06-20 18:19:05.916877882 +0200
--- src/proto/vim9compile.pro 2020-06-21 15:34:13.916728111 +0200
***************
*** 10,15 ****
--- 10,16 ----
imported_T *find_imported(char_u *name, size_t len, cctx_T *cctx);
char_u *to_name_const_end(char_u *arg);
int assignment_len(char_u *p, int *heredoc);
+ void vim9_declare_error(char_u *name);
int check_vim9_unlet(char_u *name);
int compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx);
void set_function_type(ufunc_T *ufunc);
*** ../vim-8.2.1027/src/testdir/test_vim9_expr.vim 2020-06-21 14:12:14.014668156 +0200
--- src/testdir/test_vim9_expr.vim 2020-06-21 15:35:32.996484421 +0200
***************
*** 1059,1065 ****
call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')

call CheckDefFailure(["v:nosuch += 3"], 'E1001:')
! call CheckDefFailure(["let v:statusmsg = ''"], 'E1064:')
call CheckDefFailure(["let asdf = v:nosuch"], 'E1001:')

call CheckDefFailure(["echo len('asdf'"], 'E110:')
--- 1059,1065 ----
call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')

call CheckDefFailure(["v:nosuch += 3"], 'E1001:')
! call CheckDefFailure(["let v:statusmsg = ''"], 'E1016: Cannot declare a v: variable:')
call CheckDefFailure(["let asdf = v:nosuch"], 'E1001:')

call CheckDefFailure(["echo len('asdf'"], 'E110:')
*** ../vim-8.2.1027/src/testdir/test_vim9_script.vim 2020-06-20 22:50:44.175608236 +0200
--- src/testdir/test_vim9_script.vim 2020-06-21 15:47:41.142964476 +0200
***************
*** 322,336 ****
call CheckDefFailure(['let &option'], 'E1052:')
call CheckDefFailure(['&g:option = 5'], 'E113:')

! call CheckDefFailure(['let $VAR = 5'], 'E1065:')

call CheckDefFailure(['let @~ = 5'], 'E354:')
call CheckDefFailure(['let @a = 5'], 'E1066:')

! call CheckDefFailure(['let g:var = 5'], 'E1016:')
! call CheckDefFailure(['let w:var = 5'], 'E1079:')
! call CheckDefFailure(['let b:var = 5'], 'E1078:')
! call CheckDefFailure(['let t:var = 5'], 'E1080:')

call CheckDefFailure(['let anr = 4', 'anr ..= "text"'], 'E1019:')
call CheckDefFailure(['let xnr += 4'], 'E1020:')
--- 322,336 ----
call CheckDefFailure(['let &option'], 'E1052:')
call CheckDefFailure(['&g:option = 5'], 'E113:')

! call CheckDefFailure(['let $VAR = 5'], 'E1016: Cannot declare an environment variable:')

call CheckDefFailure(['let @~ = 5'], 'E354:')
call CheckDefFailure(['let @a = 5'], 'E1066:')

! call CheckDefFailure(['let g:var = 5'], 'E1016: Cannot declare a global variable:')
! call CheckDefFailure(['let w:var = 5'], 'E1016: Cannot declare a window variable:')
! call CheckDefFailure(['let b:var = 5'], 'E1016: Cannot declare a buffer variable:')
! call CheckDefFailure(['let t:var = 5'], 'E1016: Cannot declare a tab variable:')

call CheckDefFailure(['let anr = 4', 'anr ..= "text"'], 'E1019:')
call CheckDefFailure(['let xnr += 4'], 'E1020:')
***************
*** 1812,1825 ****
CheckScriptSuccess([
'vim9script',
'g:var = 123',
! 'let w:var = 777',
'unlet g:var w:var # something',
])

CheckScriptFailure([
'vim9script',
'let g:var = 123',
! ], 'E1016:')

CheckScriptFailure([
'vim9script',
--- 1812,1852 ----
CheckScriptSuccess([
'vim9script',
'g:var = 123',
! 'b:var = 456',
! 'w:var = 777',
! 't:var = 888',
'unlet g:var w:var # something',
])

CheckScriptFailure([
'vim9script',
'let g:var = 123',
! ], 'E1016: Cannot declare a global variable:')
!
! CheckScriptFailure([
! 'vim9script',
! 'let b:var = 123',
! ], 'E1016: Cannot declare a buffer variable:')
!
! CheckScriptFailure([
! 'vim9script',
! 'let w:var = 123',
! ], 'E1016: Cannot declare a window variable:')
!
! CheckScriptFailure([
! 'vim9script',
! 'let t:var = 123',
! ], 'E1016: Cannot declare a tab variable:')
!
! CheckScriptFailure([
! 'vim9script',
! 'let v:version = 123',
! ], 'E1016: Cannot declare a v: variable:')
!
! CheckScriptFailure([
! 'vim9script',
! 'let $VARIABLE = "text"',
! ], 'E1016: Cannot declare an environment variable:')

CheckScriptFailure([
'vim9script',
*** ../vim-8.2.1027/src/version.c 2020-06-21 15:09:10.665865729 +0200
--- src/version.c 2020-06-21 15:50:40.726696578 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1028,
/**/

--
I wonder, do vegetarians eat fruit bats?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ken Takata

unread,
Jun 21, 2020, 2:01:49 PM6/21/20
to vim_dev
Hi Bram,

2020年6月21日日曜日 22時53分37秒 UTC+9 Bram Moolenaar:

Patch 8.2.1028
Problem:    Vim9: no error for declaring buffer, window, etc. variable.
Solution:   Give an error.  Unify the error messages.
Files:      src/evalvars.c, src/globals.h, src/vim9compile.c,
            src/proto/vim9compile.pro, src/testdir/test_vim9_expr.vim,
            src/testdir/test_vim9_script.vim


! EXTERN char e_declare_var[]        INIT(= N_("E1016: Cannot declare a%s variable: %s"));

This is tricky.
 
+         case 'g': scope = " global"; break;
+         case 'b': scope = " buffer"; break;
+         case 'w': scope = " window"; break;
+         case 't': scope = " tab"; break;
+         case 'v': scope = " v:"; break;
+         case '$': scope = "n environment"; break;

These strings should be translatable.

Regards,
Ken Takata

Bram Moolenaar

unread,
Jun 21, 2020, 2:38:54 PM6/21/20
to vim...@googlegroups.com, Ken Takata
I suppose that's consistent with other places where these words are
used. It won't work for "an environment", I'll make that a separate
message. Hopefully that is not needed for the other cases.

This message is only used once, but still defined in globals.h.
I'm wondering if we should either move a message like this to where it
is used, or put all messages together, and sort them on number. One
disadvantage is that the context of the message may be less clear.

--
User: I'm having problems with my text editor.
Help desk: Which editor are you using?
User: I don't know, but it's version VI (pronounced: 6).
Help desk: Oh, then you should upgrade to version VIM (pronounced: 994).

Ken Takata

unread,
Jun 21, 2020, 3:02:47 PM6/21/20
to vim_dev
Hi Bram,

2020年6月22日月曜日 3時38分54秒 UTC+9 Bram Moolenaar:

Ken Takata wrote:

> 2020年6月21日日曜日 22時53分37秒 UTC+9 Bram Moolenaar:
> >
> >
> > Patch 8.2.1028
> > Problem:    Vim9: no error for declaring buffer, window, etc. variable.
> > Solution:   Give an error.  Unify the error messages.
> > Files:      src/evalvars.c, src/globals.h, src/vim9compile.c,
> >             src/proto/vim9compile.pro, src/testdir/test_vim9_expr.vim,
> >             src/testdir/test_vim9_script.vim
> >
> >
> ! EXTERN char e_declare_var[]        INIT(= N_("E1016: Cannot declare a%s
> > variable: %s"));
> >
>
> This is tricky.
>  
>
> > +         case 'g': scope = " global"; break;
> > +         case 'b': scope = " buffer"; break;
> > +         case 'w': scope = " window"; break;
> > +         case 't': scope = " tab"; break;
> > +         case 'v': scope = " v:"; break;
> > +         case '$': scope = "n environment"; break;
>
> These strings should be translatable.

I suppose that's consistent with other places where these words are
used.  It won't work for "an environment", I'll make that a separate
message.  Hopefully that is not needed for the other cases.

How about this?

EXTERN char e_declare_var[]    INIT(= N_("E1016: Cannot declare %s variable: %s"));

    case 'g': scope = _("a global"); break;
    case 'b': scope = _("a buffer"); break;
    case 'w': scope = _("a window"); break;
    case 't': scope = _("a tab"); break;
    case 'v': scope = _("a v:"); break;
    case '$': scope = _("an environment"); break;

 
This message is only used once, but still defined in globals.h.
I'm wondering if we should either move a message like this to where it
is used, or put all messages together, and sort them on number.  One
disadvantage is that the context of the message may be less clear.
 
Regards,
Ken Takata
Reply all
Reply to author
Forward
0 new messages