diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-04-06 21:17:27 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-04-06 21:17:27 +0200 |
commit | 643ce6c0c694667a2afd24bb39d8e9d36d94d7a9 (patch) | |
tree | e9fb101fb1bc6e4b24291bcdf8100c1428af0bfe /src | |
parent | e3d1f4c982bd0fe05496448d7868268c75ff7bfb (diff) |
patch 8.2.2729: Vim9: wrong error message for referring to legacy script varv8.2.2729
Problem: Vim9: wrong error message for referring to legacy script variable.
Solution: Do allow referring to a variable in legacy script without "s:" if
it exists at compile time. (closes #8076)
Diffstat (limited to 'src')
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 35 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 14 |
3 files changed, 40 insertions, 11 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 73351b44f4..c35084d550 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1476,6 +1476,41 @@ def Test_var_declaration_fails() CheckDefFailure(['const foo: number'], 'E1021:') enddef +def Test_script_local_in_legacy() + # OK to define script-local later when prefixed with s: + var lines =<< trim END + def SetLater() + s:legacy = 'two' + enddef + defcompile + let s:legacy = 'one' + call SetLater() + call assert_equal('two', s:legacy) + END + CheckScriptSuccess(lines) + + # OK to leave out s: prefix when script-local already defined + lines =<< trim END + let s:legacy = 'one' + def SetNoPrefix() + legacy = 'two' + enddef + call SetNoPrefix() + call assert_equal('two', s:legacy) + END + CheckScriptSuccess(lines) + + # Not OK to leave out s: prefix when script-local defined later + lines =<< trim END + def SetLaterNoPrefix() + legacy = 'two' + enddef + defcompile + let s:legacy = 'one' + END + CheckScriptFailure(lines, 'E476:', 1) +enddef + def Test_var_type_check() var lines =<< trim END vim9script diff --git a/src/version.c b/src/version.c index f041987844..8d44824a19 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2729, +/**/ 2728, /**/ 2727, diff --git a/src/vim9compile.c b/src/vim9compile.c index 6ff00f7d49..c9ca5953fc 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -5708,17 +5708,9 @@ generate_store_var( return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL); case dest_script: if (scriptvar_idx < 0) - { - char_u *name_s = name; - int r; - - // "s:" is included in the name. - r = generate_OLDSCRIPT(cctx, ISN_STORES, name_s, + // "s:" may be included in the name. + return generate_OLDSCRIPT(cctx, ISN_STORES, name, scriptvar_sid, type); - if (name_s != name) - vim_free(name_s); - return r; - } return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT, scriptvar_sid, scriptvar_idx, type); case dest_local: @@ -5854,7 +5846,7 @@ compile_lhs( ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2, FALSE, cctx) : script_var_exists(var_start, lhs->lhs_varlen, - TRUE, cctx)) == OK; + FALSE, cctx)) == OK; imported_T *import = find_imported(var_start, lhs->lhs_varlen, cctx); |