0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -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:
h-east
2023-04-18 19:07:29 +01:00
committed by Bram Moolenaar
parent 89f9ffbe81
commit 61378a1542
3 changed files with 22 additions and 18 deletions

View File

@@ -995,7 +995,7 @@ def Test_interface_basics()
def Method(count: number)
endinterface
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
vim9script
@@ -1005,7 +1005,9 @@ def Test_interface_basics()
def Method(value: number)
endinterface
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
vim9script

View File

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

View File

@@ -737,7 +737,9 @@ early_ret:
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)
{
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)
{
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
// OK. TODO: check for the "this." prefix.
if (STRNCMP(uf->uf_name, "new", 3) == 0 && 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)
{
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),
success = FALSE;
if (uf->uf_script_ctx.sc_sid > 0)
SOURCING_LNUM = uf->uf_script_ctx.sc_lnum;
semsg(_(e_argument_already_declared_in_class_str),
aname);
break;
}
break;
}
}
}