0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.0.1192: no error when class function argument shadows a member

Problem:    No error when class function argument shadows a member.
Solution:   Check for shadowing.
This commit is contained in:
Bram Moolenaar 2023-01-13 17:36:49 +00:00
parent 3213952966
commit d40f00cb43
3 changed files with 53 additions and 2 deletions

View File

@ -639,8 +639,17 @@ def Test_interface_basics()
def Method(count: number)
endinterface
END
# TODO: this should give an error for "count" shadowing
v9.CheckScriptSuccess(lines)
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
lines =<< trim END
vim9script
interface Some
this.value: number
def Method(value: number)
endinterface
END
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: value')
lines =<< trim END
vim9script

View File

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

View File

@ -699,6 +699,46 @@ early_ret:
}
}
if (success)
{
// Check no function argument name is used as an object/class member.
for (int loop = 1; loop <= 2 && success; ++loop)
{
garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
for (int fi = 0; fi < gap->ga_len && success; ++fi)
{
ufunc_T *uf = ((ufunc_T **)gap->ga_data)[fi];
for (int i = 0; i < uf->uf_args.ga_len && success; ++i)
{
char_u *aname = ((char_u **)uf->uf_args.ga_data)[i];
for (int il = 1; il <= 2 && success; ++il)
{
// For a "new()" function "this.member" arguments are
// OK. TODO: check for the "this." prefix.
if (STRNCMP(uf->uf_name, "new", 3) == NULL && il == 2)
continue;
garray_T *mgap = il == 1 ? &classmembers : &objmembers;
for (int mi = 0; mi < mgap->ga_len; ++mi)
{
char_u *mname = ((ocmember_T *)mgap->ga_data
+ mi)->ocm_name;
if (STRCMP(aname, mname) == 0)
{
success = FALSE;
semsg(_(e_argument_already_declared_in_class_str),
aname);
break;
}
}
}
}
}
}
}
class_T *cl = NULL;
if (success)
{