Patch 9.0.1192

9 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 13, 2023, 12:37:23 PM1/13/23
to vim...@googlegroups.com

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 -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Jan 13, 2023, 1:40:17 PM1/13/23
to vim...@googlegroups.com

On 14-Jan-2023 04:37, Bram Moolenaar wrote:
> 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
>
>
After this patch, msys64 (clang 15.0.5) gives this warning:
<snip>
clang -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -Wall -O3 -fomit-frame-pointer -fpie -fPIE -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD vim9class.c -o gobjx86-64/vim9class.o
vim9class.c:720:39: warning: comparison between pointer and integer
('int' and 'void *') [-Wpointer-integer-compare]
                        if (STRNCMP(uf->uf_name, "new", 3) == NULL &&
il == 2)
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
1 warning generated.
</snip>

The attached patch tries to fix it. I hope I have the logic the right
way around. 😁

Cheers
John
vim9class.c.9.0.1192.patch

Bram Moolenaar

unread,
Jan 13, 2023, 2:30:47 PM1/13/23
to vim...@googlegroups.com, John Marriott
Yeah, the value of NULL is zero. I didn't spot the warning when
compiling locally. Patch 9.0.1194 has the same fix.

--
hundred-and-one symptoms of being an internet addict:
3. Your bookmark takes 15 minutes to scroll from top to bottom.
Reply all
Reply to author
Forward
0 new messages