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:
parent
3213952966
commit
d40f00cb43
@ -639,8 +639,17 @@ def Test_interface_basics()
|
|||||||
def Method(count: number)
|
def Method(count: number)
|
||||||
endinterface
|
endinterface
|
||||||
END
|
END
|
||||||
# TODO: this should give an error for "count" shadowing
|
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
|
||||||
v9.CheckScriptSuccess(lines)
|
|
||||||
|
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
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@ -695,6 +695,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 */
|
||||||
|
/**/
|
||||||
|
1192,
|
||||||
/**/
|
/**/
|
||||||
1191,
|
1191,
|
||||||
/**/
|
/**/
|
||||||
|
@ -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;
|
class_T *cl = NULL;
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user