Patch 8.2.4102
Problem:    Vim9: import cannot be used after method.
Solution:   Recognize an imported function name. (closes #9496)
Files:      src/eval.c, src/testdir/test_vim9_import.vim


*** ../vim-8.2.4101/src/eval.c  2022-01-12 15:15:22.871212756 +0000
--- src/eval.c  2022-01-15 20:55:50.035565800 +0000
***************
*** 3949,3955 ****
      long      len;
      char_u    *alias;
      typval_T  base = *rettv;
!     int               ret;
      int               evaluate = evalarg != NULL
                                      && (evalarg->eval_flags & EVAL_EVALUATE);
  
--- 3949,3955 ----
      long      len;
      char_u    *alias;
      typval_T  base = *rettv;
!     int               ret = OK;
      int               evaluate = evalarg != NULL
                                      && (evalarg->eval_flags & EVAL_EVALUATE);
  
***************
*** 3968,3989 ****
      }
      else
      {
!       *arg = skipwhite(*arg);
!       if (**arg != '(')
        {
!           if (verbose)
!               semsg(_(e_missing_parenthesis_str), name);
!           ret = FAIL;
        }
!       else if (VIM_ISWHITE((*arg)[-1]))
        {
!           if (verbose)
!               emsg(_(e_no_white_space_allowed_before_parenthesis));
!           ret = FAIL;
!       }
!       else
!           ret = eval_func(arg, evalarg, name, len, rettv,
                                          evaluate ? EVAL_EVALUATE : 0, &base);
      }
  
      // Clear the funcref afterwards, so that deleting it while
--- 3968,4054 ----
      }
      else
      {
!       if (**arg == '.')
        {
!           int         len2;
!           char_u      *fname;
!           int         idx;
!           imported_T  *import = find_imported(name, len,
!                                                    TRUE, evalarg->eval_cctx);
!           type_T      *type;
! 
!           // value->import.func()
!           if (import != NULL)
!           {
!               name = NULL;
!               ++*arg;
!               fname = *arg;
!               len2 = get_name_len(arg, &alias, evaluate, TRUE);
!               if (len2 <= 0)
!               {
!                   emsg(_(e_missing_name_after_dot));
!                   ret = FAIL;
!               }
!               else
!               {
!                   int     cc = fname[len2];
!                   ufunc_T *ufunc;
! 
!                   fname[len2] = NUL;
!                   idx = find_exported(import->imp_sid, fname, &ufunc, &type,
!                                                 evalarg->eval_cctx, verbose);
!                   fname[len2] = cc;
! 
!                   if (idx >= 0)
!                   {
!                       scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
!                       svar_T          *sv =
!                                    ((svar_T *)si->sn_var_vals.ga_data) + idx;
! 
!                       if (sv->sv_tv->v_type == VAR_FUNC
!                                          && sv->sv_tv->vval.v_string != NULL)
!                       {
!                           name = sv->sv_tv->vval.v_string;
!                           len = STRLEN(name);
!                       }
!                       else
!                       {
!                           // TODO: how about a partial?
!                           semsg(_(e_not_callable_type_str), fname);
!                           ret = FAIL;
!                       }
!                   }
!                   else if (ufunc != NULL)
!                   {
!                       name = ufunc->uf_name;
!                       len = STRLEN(name);
!                   }
!                   else
!                       ret = FAIL;
!               }
!           }
        }
! 
!       if (ret == OK)
        {
!           *arg = skipwhite(*arg);
! 
!           if (**arg != '(')
!           {
!               if (verbose)
!                   semsg(_(e_missing_parenthesis_str), name);
!               ret = FAIL;
!           }
!           else if (VIM_ISWHITE((*arg)[-1]))
!           {
!               if (verbose)
!                   emsg(_(e_no_white_space_allowed_before_parenthesis));
!               ret = FAIL;
!           }
!           else
!               ret = eval_func(arg, evalarg, name, len, rettv,
                                          evaluate ? EVAL_EVALUATE : 0, &base);
+       }
      }
  
      // Clear the funcref afterwards, so that deleting it while
*** ../vim-8.2.4101/src/testdir/test_vim9_import.vim    2022-01-15 
18:25:04.661419379 +0000
--- src/testdir/test_vim9_import.vim    2022-01-15 21:03:45.491219397 +0000
***************
*** 27,32 ****
--- 27,36 ----
      exported += 5
    enddef
    export final theList = [1]
+   export def AddSome(s: string): string
+     return s .. 'some'
+   enddef
+   export var AddRef = AddSome
  END
  
  def Undo_export_script_lines()
***************
*** 70,75 ****
--- 74,82 ----
  
      expo.theList->add(2)
      assert_equal([1, 2], expo.theList)
+ 
+     assert_equal('andthensome', 'andthen'->expo.AddSome())
+     assert_equal('awesome', 'awe'->expo.AddRef())
    END
    writefile(import_script_lines, 'Ximport.vim')
    source Ximport.vim
*** ../vim-8.2.4101/src/version.c       2022-01-15 18:48:28.602361973 +0000
--- src/version.c       2022-01-15 20:57:26.339450546 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4102,
  /**/

-- 
GUARD #1:  What -- a swallow carrying a coconut?
ARTHUR:    It could grip it by the husk!
GUARD #1:  It's not a question of where he grips it!  It's a simple question
           of weight ratios!  A five ounce bird could not carry a 1 pound
           coconut.
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- b...@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    ///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220115210900.149D61C03C8%40moolenaar.net.

Raspunde prin e-mail lui