Patch 9.0.1466
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.
Files:      src/vim9class.c, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1465/src/vim9class.c     2023-03-11 20:56:30.660063861 +0000
--- src/vim9class.c     2023-04-18 19:05:31.498868050 +0100
***************
*** 737,743 ****
  
      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;
--- 737,745 ----
  
      if (success)
      {
!       // 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,772 ****
                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) == 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)
!                           {
!                               success = FALSE;
!                               
semsg(_(e_argument_already_declared_in_class_str),
                                                                        aname);
!                               break;
!                           }
                        }
                    }
                }
--- 751,772 ----
                for (int i = 0; i < uf->uf_args.ga_len && success; ++i)
                {
                    char_u *aname = ((char_u **)uf->uf_args.ga_data)[i];
!                   garray_T *mgap = &classmembers;
! 
!                   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;
! 
!                           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;
                        }
                    }
                }
*** ../vim-9.0.1465/src/testdir/test_vim9_class.vim     2023-03-11 
20:56:30.660063861 +0000
--- src/testdir/test_vim9_class.vim     2023-04-18 18:45:17.358677624 +0100
***************
*** 995,1001 ****
          def Method(count: number)
        endinterface
    END
!   v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the 
class: count')
  
    lines =<< trim END
        vim9script
--- 995,1001 ----
          def Method(count: number)
        endinterface
    END
!   v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the 
class: count', 5)
  
    lines =<< trim END
        vim9script
***************
*** 1005,1011 ****
          def Method(value: number)
        endinterface
    END
!   v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the 
class: value')
  
    lines =<< trim END
        vim9script
--- 1005,1013 ----
          def Method(value: number)
        endinterface
    END
!   # 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
*** ../vim-9.0.1465/src/version.c       2023-04-18 17:20:05.217542787 +0100
--- src/version.c       2023-04-18 18:41:33.450682382 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1466,
  /**/

-- 
Close your shells, or I'll kill -9 you
Tomorrow I'll quota you
Remember the disks'll always be full
And then while I'm away
I'll write ~ everyday
And I'll send-pr all my buggings to you.
    [ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ]

 /// 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/20230418180804.6A2C91C03FD%40moolenaar.net.

Raspunde prin e-mail lui