mirror of
https://github.com/vim/vim.git
synced 2025-10-16 07:24:23 -04:00
patch 9.1.1828: local variables shadowed by import names
Problem: local variables shadowed by import names Solution: Check if a local variable exists before handling imports (thinca) closes: #18480 Signed-off-by: thinca <thinca@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
f3d0d08907
commit
6858587761
32
src/eval.c
32
src/eval.c
@@ -2236,13 +2236,33 @@ get_lval(
|
|||||||
|
|
||||||
if (*p == '.')
|
if (*p == '.')
|
||||||
{
|
{
|
||||||
imported_T *import = find_imported(lp->ll_name, p - lp->ll_name, TRUE);
|
// In legacy script, when a local variable and import exists with this name,
|
||||||
if (import != NULL)
|
// prioritize local variable over imports to avoid conflicts.
|
||||||
|
int var_exists = FALSE;
|
||||||
|
if (!vim9script)
|
||||||
{
|
{
|
||||||
p++; // skip '.'
|
cc = *p;
|
||||||
p = get_lval_imported(lp, import->imp_sid, p, &v, fne_flags);
|
*p = NUL;
|
||||||
if (p == NULL)
|
hashtab_T *local_ht = get_funccal_local_ht();
|
||||||
return NULL;
|
if (local_ht != NULL)
|
||||||
|
{
|
||||||
|
hashitem_T *hi = hash_find(local_ht, lp->ll_name);
|
||||||
|
if (!HASHITEM_EMPTY(hi))
|
||||||
|
var_exists = TRUE;
|
||||||
|
}
|
||||||
|
*p = cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!var_exists)
|
||||||
|
{
|
||||||
|
imported_T *import = find_imported(lp->ll_name, p - lp->ll_name, TRUE);
|
||||||
|
if (import != NULL)
|
||||||
|
{
|
||||||
|
p++; // skip '.'
|
||||||
|
p = get_lval_imported(lp, import->imp_sid, p, &v, fne_flags);
|
||||||
|
if (p == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3694,4 +3694,29 @@ def Test_import_member_initializer()
|
|||||||
v9.CheckScriptSuccess(lines)
|
v9.CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_import_name_conflict_with_local_variable()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
export class Foo
|
||||||
|
def Method(): string
|
||||||
|
return 'Method'
|
||||||
|
enddef
|
||||||
|
endclass
|
||||||
|
END
|
||||||
|
writefile(lines, 'Xvim9.vim', 'D')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
import './Xvim9.vim'
|
||||||
|
|
||||||
|
function! s:Main() abort
|
||||||
|
let Xvim9 = s:Xvim9.Foo.new()
|
||||||
|
call assert_equal('Method', Xvim9.Method())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call s:Main()
|
||||||
|
END
|
||||||
|
v9.CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||||
|
@@ -729,6 +729,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1828,
|
||||||
/**/
|
/**/
|
||||||
1827,
|
1827,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user