Patch 9.0.1192
Problem: No error when class function argument shadows a member.
Solution: Check for shadowing.
Files: src/vim9class.c, src/testdir/test_vim9_class.vim
*** ../vim-9.0.1191/src/vim9class.c 2023-01-12 17:06:24.136720890 +0000
--- src/vim9class.c 2023-01-13 16:43:39.342127617 +0000
***************
*** 699,704 ****
--- 699,744 ----
}
}
+ 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)
{
*** ../vim-9.0.1191/src/testdir/test_vim9_class.vim 2023-01-12
21:07:58.640905098 +0000
--- src/testdir/test_vim9_class.vim 2023-01-13 16:44:12.398142634 +0000
***************
*** 639,646 ****
def Method(count: number)
endinterface
END
! # TODO: this should give an error for "count" shadowing
! v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
--- 639,655 ----
def Method(count: number)
endinterface
END
! 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
*** ../vim-9.0.1191/src/version.c 2023-01-13 15:35:14.147630709 +0000
--- src/version.c 2023-01-13 16:28:32.245705039 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1192,
/**/
--
A)bort, R)etry, P)lease don't bother me again
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230113173718.DECA91C0916%40moolenaar.net.