Patch 8.2.2734
Problem: Vim9: cannot use legacy script-local var from :def function.
Solution: Do not insist on using "s:" prefix. (closes #8076)
Files: src/vim9compile.c, src/proto/vim9compile.pro,
src/testdir/test_vim9_expr.vim
*** ../vim-8.2.2733/src/vim9compile.c 2021-04-06 21:29:28.928203312 +0200
--- src/vim9compile.c 2021-04-07 21:13:52.094687077 +0200
***************
*** 332,353 ****
/*
* Lookup a variable (without s: prefix) in the current script.
- * If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
- * without "s:".
* "cctx" is NULL at the script level.
* Returns OK or FAIL.
*/
! int
! script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
{
- int is_vim9_script;
-
if (current_sctx.sc_sid <= 0)
return FAIL;
! is_vim9_script = script_is_vim9();
! if (vim9script && !is_vim9_script)
! return FAIL;
! if (is_vim9_script)
{
// Check script variables that were visible where the function was
// defined.
--- 332,346 ----
/*
* Lookup a variable (without s: prefix) in the current script.
* "cctx" is NULL at the script level.
* Returns OK or FAIL.
*/
! static int
! script_var_exists(char_u *name, size_t len, cctx_T *cctx)
{
if (current_sctx.sc_sid <= 0)
return FAIL;
! if (script_is_vim9())
{
// Check script variables that were visible where the function was
// defined.
***************
*** 382,388 ****
return (cctx != NULL
&& (lookup_local(name, len, NULL, cctx) == OK
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
! || script_var_exists(name, len, FALSE, cctx) == OK
|| find_imported(name, len, cctx) != NULL;
}
--- 375,381 ----
return (cctx != NULL
&& (lookup_local(name, len, NULL, cctx) == OK
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
! || script_var_exists(name, len, cctx) == OK
|| find_imported(name, len, cctx) != NULL;
}
***************
*** 429,435 ****
int c = p[len];
ufunc_T *ufunc = NULL;
! if (script_var_exists(p, len, FALSE, cctx) == OK)
{
if (is_arg)
semsg(_(e_argument_already_declared_in_script_str), p);
--- 422,428 ----
int c = p[len];
ufunc_T *ufunc = NULL;
! if (script_var_exists(p, len, cctx) == OK)
{
if (is_arg)
semsg(_(e_argument_already_declared_in_script_str), p);
***************
*** 2990,2996 ****
{
// "var" can be script-local even without using "s:" if it
// already exists in a Vim9 script or when it's imported.
! if (script_var_exists(*arg, len, TRUE, cctx) == OK
|| find_imported(name, 0, cctx) != NULL)
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
--- 2983,2989 ----
{
// "var" can be script-local even without using "s:" if it
// already exists in a Vim9 script or when it's imported.
! if (script_var_exists(*arg, len, cctx) == OK
|| find_imported(name, 0, cctx) != NULL)
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
***************
*** 5844,5852 ****
&& STRNCMP(var_start, "s:", 2) == 0;
int script_var = (script_namespace
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
! FALSE, cctx)
: script_var_exists(var_start, lhs->lhs_varlen,
! FALSE, cctx)) == OK;
imported_T *import =
find_imported(var_start, lhs->lhs_varlen, cctx);
--- 5837,5845 ----
&& STRNCMP(var_start, "s:", 2) == 0;
int script_var = (script_namespace
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
! cctx)
: script_var_exists(var_start, lhs->lhs_varlen,
! cctx)) == OK;
imported_T *import =
find_imported(var_start, lhs->lhs_varlen, cctx);
*** ../vim-8.2.2733/src/proto/vim9compile.pro 2021-03-21 20:53:24.930400991
+0100
--- src/proto/vim9compile.pro 2021-04-07 21:13:55.070681764 +0200
***************
*** 1,5 ****
/* vim9compile.c */
- int script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx);
int check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg);
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
int use_typecheck(type_T *actual, type_T *expected);
--- 1,4 ----
*** ../vim-8.2.2733/src/testdir/test_vim9_expr.vim 2021-04-05
19:41:17.139727625 +0200
--- src/testdir/test_vim9_expr.vim 2021-04-07 21:17:24.018285089 +0200
***************
*** 2714,2719 ****
--- 2714,2734 ----
CheckDefAndScriptFailure(lines, 'E1050:')
enddef
+ def Test_expr7_legacy_script()
+ var lines =<< trim END
+ let s:legacy = 'legacy'
+ def GetLocal(): string
+ return legacy
+ enddef
+ def GetLocalPrefix(): string
+ return s:legacy
+ enddef
+ call assert_equal('legacy', GetLocal())
+ call assert_equal('legacy', GetLocalPrefix())
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
def Echo(arg: any): string
return arg
enddef
*** ../vim-8.2.2733/src/version.c 2021-04-07 20:11:07.987846226 +0200
--- src/version.c 2021-04-07 21:11:15.510950003 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2734,
/**/
--
hundred-and-one symptoms of being an internet addict:
85. Choice between paying Compuserve bill and paying for kids education
is a no brainer -- although a bit painful for your kids.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202104071921.137JLlCx3682673%40masaka.moolenaar.net.