mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.1466: cannot use an object member name as a method argument
Problem: Cannot use an object member name as a method argument. Solution: Do not give an error for using an object member name for a method argument. (Hirohito Higashi, closes #12241, closes #12225) Fix line number for other argument error.
This commit is contained in:
@@ -995,7 +995,7 @@ def Test_interface_basics()
|
|||||||
def Method(count: number)
|
def Method(count: number)
|
||||||
endinterface
|
endinterface
|
||||||
END
|
END
|
||||||
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
|
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count', 5)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@@ -1005,7 +1005,9 @@ def Test_interface_basics()
|
|||||||
def Method(value: number)
|
def Method(value: number)
|
||||||
endinterface
|
endinterface
|
||||||
END
|
END
|
||||||
v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: value')
|
# The argument name and the object member name are the same, but this is not a
|
||||||
|
# problem because object members are always accessed with the "this." prefix.
|
||||||
|
v9.CheckScriptSuccess(lines)
|
||||||
|
|
||||||
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 */
|
||||||
|
/**/
|
||||||
|
1466,
|
||||||
/**/
|
/**/
|
||||||
1465,
|
1465,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -737,7 +737,9 @@ early_ret:
|
|||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// Check no function argument name is used as an object/class member.
|
// Check no function argument name is used as a class member.
|
||||||
|
// (Object members are always accessed with "this." prefix, so no need
|
||||||
|
// to check them.)
|
||||||
for (int loop = 1; loop <= 2 && success; ++loop)
|
for (int loop = 1; loop <= 2 && success; ++loop)
|
||||||
{
|
{
|
||||||
garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
|
garray_T *gap = loop == 1 ? &classfunctions : &objmethods;
|
||||||
@@ -749,24 +751,22 @@ early_ret:
|
|||||||
for (int i = 0; i < uf->uf_args.ga_len && success; ++i)
|
for (int i = 0; i < uf->uf_args.ga_len && success; ++i)
|
||||||
{
|
{
|
||||||
char_u *aname = ((char_u **)uf->uf_args.ga_data)[i];
|
char_u *aname = ((char_u **)uf->uf_args.ga_data)[i];
|
||||||
for (int il = 1; il <= 2 && success; ++il)
|
garray_T *mgap = &classmembers;
|
||||||
|
|
||||||
|
for (int mi = 0; mi < mgap->ga_len; ++mi)
|
||||||
{
|
{
|
||||||
// For a "new()" function "this.member" arguments are
|
char_u *mname = ((ocmember_T *)mgap->ga_data + mi)
|
||||||
// OK. TODO: check for the "this." prefix.
|
->ocm_name;
|
||||||
if (STRNCMP(uf->uf_name, "new", 3) == 0 && il == 2)
|
if (STRCMP(aname, mname) == 0)
|
||||||
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
|
success = FALSE;
|
||||||
+ mi)->ocm_name;
|
|
||||||
if (STRCMP(aname, mname) == 0)
|
if (uf->uf_script_ctx.sc_sid > 0)
|
||||||
{
|
SOURCING_LNUM = uf->uf_script_ctx.sc_lnum;
|
||||||
success = FALSE;
|
|
||||||
semsg(_(e_argument_already_declared_in_class_str),
|
semsg(_(e_argument_already_declared_in_class_str),
|
||||||
aname);
|
aname);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user