Patch 9.0.0366
Problem:    Cannot use import->Func() in lambda. (Israel Chauca Fuentes)
Solution:   Adjust how an expression in a lambda is parsed. (closes #11042)
Files:      src/eval.c, src/testdir/test_vim9_import.vim


*** ../vim-9.0.0365/src/eval.c  2022-09-02 12:16:01.876714257 +0100
--- src/eval.c  2022-09-03 11:51:56.237791288 +0100
***************
*** 694,701 ****
--- 694,708 ----
  {
      typval_T  ref;
      char_u    *name = *arg;
+     int               save_flags;
  
      ref.v_type = VAR_UNKNOWN;
+     if (evalarg != NULL)
+     {
+       // need to evaluate this to get an import, like in "a.Func"
+       save_flags = evalarg->eval_flags;
+       evalarg->eval_flags |= EVAL_EVALUATE;
+     }
      if (eval9(arg, &ref, evalarg, FALSE) == FAIL)
      {
        dictitem_T      *v;
***************
*** 703,709 ****
        // If <SID>VarName was used it would not be found, try another way.
        v = find_var_also_in_script(name, NULL, FALSE);
        if (v == NULL)
!           return NULL;
        copy_tv(&v->di_tv, &ref);
      }
      if (*skipwhite(*arg) != NUL)
--- 710,719 ----
        // If <SID>VarName was used it would not be found, try another way.
        v = find_var_also_in_script(name, NULL, FALSE);
        if (v == NULL)
!       {
!           name = NULL;
!           goto theend;
!       }
        copy_tv(&v->di_tv, &ref);
      }
      if (*skipwhite(*arg) != NUL)
***************
*** 739,745 ****
--- 749,759 ----
            semsg(_(e_not_callable_type_str), name);
        name = NULL;
      }
+ 
+ theend:
      clear_tv(&ref);
+     if (evalarg != NULL)
+       evalarg->eval_flags = save_flags;
      return name;
  }
  
***************
*** 4080,4086 ****
      // Handle following '[', '(' and '.' for expr[expr], expr.name,
      // expr(expr), expr->name(expr)
      if (ret == OK)
!       ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE);
  
      /*
       * Apply logical NOT and unary '-', from right to left, ignore '+'.
--- 4094,4100 ----
      // Handle following '[', '(' and '.' for expr[expr], expr.name,
      // expr(expr), expr->name(expr)
      if (ret == OK)
!       ret = handle_subscript(arg, name_start, rettv, evalarg, evaluate);
  
      /*
       * Apply logical NOT and unary '-', from right to left, ignore '+'.
***************
*** 4349,4355 ****
      rettv->v_type = VAR_UNKNOWN;
  
      name = *arg;
!     len = get_name_len(arg, &alias, evaluate, TRUE);
      if (alias != NULL)
        name = alias;
  
--- 4363,4369 ----
      rettv->v_type = VAR_UNKNOWN;
  
      name = *arg;
!     len = get_name_len(arg, &alias, evaluate, evaluate);
      if (alias != NULL)
        name = alias;
  
*** ../vim-9.0.0365/src/testdir/test_vim9_import.vim    2022-09-02 
21:55:45.511049444 +0100
--- src/testdir/test_vim9_import.vim    2022-09-03 11:59:39.368291127 +0100
***************
*** 1454,1459 ****
--- 1454,1481 ----
    set nospell spellsuggest& verbose=0
  enddef
  
+ def Test_import_in_lambda_method()
+   var lines =<< trim END
+       vim9script
+       export def Retarg(e: any): any
+         return e
+       enddef
+   END
+   writefile(lines, 'XexportRetarg.vim')
+   lines =<< trim END
+       vim9script
+       import './XexportRetarg.vim'
+       def Lambda(): string
+         var F = (x) => x->XexportRetarg.Retarg()
+         return F('arg')
+       enddef
+       assert_equal('arg', Lambda())
+   END
+   v9.CheckScriptSuccess(lines)
+ 
+   delete('XexportRetarg.vim')
+ enddef
+ 
  def Test_export_shadows_global_function()
    mkdir('Xglobdir/autoload', 'p')
    var save_rtp = &rtp
*** ../vim-9.0.0365/src/version.c       2022-09-03 10:59:28.716487461 +0100
--- src/version.c       2022-09-03 11:59:09.912416857 +0100
***************
*** 709,710 ****
--- 709,712 ----
  {   /* Add new patch number below this line */
+ /**/
+     366,
  /**/

-- 
You can test a person's importance in the organization by asking how much RAM
his computer has.  Anybody who knows the answer to that question is not a
decision-maker.
                                (Scott Adams - The Dilbert principle)

 /// 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/20220903110946.307111C0CE4%40moolenaar.net.

Raspunde prin e-mail lui