Patch 9.0.1569
Problem:    Cannot use "this.member" in lambda in class method.
Solution:   Adjust check for reserved keyword. (Hirohito Higashi,
            closes #12416, closes #12076, closes #12336)
Files:      src/eval.c, src/vim9compile.c, src/vim9script.c,
            src/proto/vim9script.pro, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1568/src/eval.c  2023-05-05 17:22:31.965659631 +0100
--- src/eval.c  2023-05-19 18:49:56.983135489 +0100
***************
*** 1654,1660 ****
      {
        cc = *endp;
        *endp = NUL;
!       if (in_vim9script() && check_reserved_name(lp->ll_name, NULL) == FAIL)
            return;
  
        if (lp->ll_blob != NULL)
--- 1654,1660 ----
      {
        cc = *endp;
        *endp = NUL;
!       if (in_vim9script() && check_reserved_name(lp->ll_name, FALSE) == FAIL)
            return;
  
        if (lp->ll_blob != NULL)
*** ../vim-9.0.1568/src/vim9compile.c   2023-05-14 22:05:09.813326337 +0100
--- src/vim9compile.c   2023-05-19 18:49:56.983135489 +0100
***************
*** 1580,1586 ****
        else
        {
            // No specific kind of variable recognized, just a name.
!           if (check_reserved_name(lhs->lhs_name, cctx) == FAIL)
                return FAIL;
  
            if (lookup_local(var_start, lhs->lhs_varlen,
--- 1580,1587 ----
        else
        {
            // No specific kind of variable recognized, just a name.
!           if (check_reserved_name(lhs->lhs_name, lhs->lhs_has_index
!                                               && *var_end == '.') == FAIL)
                return FAIL;
  
            if (lookup_local(var_start, lhs->lhs_varlen,
*** ../vim-9.0.1568/src/vim9script.c    2023-03-07 17:13:47.317107770 +0000
--- src/vim9script.c    2023-05-19 18:49:56.983135489 +0100
***************
*** 838,844 ****
      // parse type, check for reserved name
      p = skipwhite(p + 1);
      type = parse_type(&p, &si->sn_type_list, TRUE);
!     if (type == NULL || check_reserved_name(name, NULL) == FAIL)
      {
        vim_free(name);
        return p;
--- 838,844 ----
      // parse type, check for reserved name
      p = skipwhite(p + 1);
      type = parse_type(&p, &si->sn_type_list, TRUE);
!     if (type == NULL || check_reserved_name(name, FALSE) == FAIL)
      {
        vim_free(name);
        return p;
***************
*** 1127,1143 ****
  };
  
      int
! check_reserved_name(char_u *name, cctx_T *cctx)
  {
      int idx;
  
      for (idx = 0; reserved[idx] != NULL; ++idx)
        if (STRCMP(reserved[idx], name) == 0
!               // "this" can be used in an object method
!               && !(STRCMP("this", name) == 0
!                   && cctx != NULL
!                   && cctx->ctx_ufunc != NULL
!                   && (cctx->ctx_ufunc->uf_flags & (FC_OBJECT|FC_NEW))))
        {
            semsg(_(e_cannot_use_reserved_name_str), name);
            return FAIL;
--- 1127,1139 ----
  };
  
      int
! check_reserved_name(char_u *name, int is_objm_access)
  {
      int idx;
  
      for (idx = 0; reserved[idx] != NULL; ++idx)
        if (STRCMP(reserved[idx], name) == 0
!               && !(STRCMP("this", name) == 0 && is_objm_access))
        {
            semsg(_(e_cannot_use_reserved_name_str), name);
            return FAIL;
*** ../vim-9.0.1568/src/proto/vim9script.pro    2022-12-08 15:32:11.087034211 
+0000
--- src/proto/vim9script.pro    2023-05-19 18:59:40.232161580 +0100
***************
*** 19,23 ****
  void hide_script_var(scriptitem_T *si, int idx, int func_defined);
  svar_T *find_typval_in_script(typval_T *dest, scid_T sid, int must_find);
  int check_script_var_type(svar_T *sv, typval_T *value, char_u *name, where_T 
where);
! int check_reserved_name(char_u *name, cctx_T *cctx);
  /* vim: set ft=c : */
--- 19,23 ----
  void hide_script_var(scriptitem_T *si, int idx, int func_defined);
  svar_T *find_typval_in_script(typval_T *dest, scid_T sid, int must_find);
  int check_script_var_type(svar_T *sv, typval_T *value, char_u *name, where_T 
where);
! int check_reserved_name(char_u *name, int is_objm_access);
  /* vim: set ft=c : */
*** ../vim-9.0.1568/src/testdir/test_vim9_class.vim     2023-04-24 
17:15:20.371257120 +0100
--- src/testdir/test_vim9_class.vim     2023-05-19 18:49:56.983135489 +0100
***************
*** 856,861 ****
--- 856,882 ----
    END
    v9.CheckScriptSuccess(lines)
  
+   # access private member in lambda body
+   lines =<< trim END
+       vim9script
+ 
+       class Foo
+         this._x: number = 6
+ 
+         def Add(n: number): number
+           var Lam = () => {
+             this._x = this._x + n
+           }
+           Lam()
+           return this._x
+         enddef
+       endclass
+ 
+       var foo = Foo.new()
+       assert_equal(13, foo.Add(7))
+   END
+   v9.CheckScriptSuccess(lines)
+ 
    # check shadowing
    lines =<< trim END
        vim9script
*** ../vim-9.0.1568/src/version.c       2023-05-19 14:04:23.137885851 +0100
--- src/version.c       2023-05-19 18:52:45.526968814 +0100
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1569,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
43. You tell the kids they can't use the computer because "Daddy's got work to
    do" and you don't even have a job.

 /// 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/20230519180142.734281C0CF3%40moolenaar.net.

Raspunde prin e-mail lui