• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révision648a5f6589904ee2a015223fd567dfeef197f2bb (tree)
l'heure2022-01-16 06:15:03
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.4102: Vim9: import cannot be used after method

Commit: https://github.com/vim/vim/commit/857c8bb1bbe754cf2c5b709703d2eb848c800285
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 15 21:08:19 2022 +0000

patch 8.2.4102: Vim9: import cannot be used after method
Problem: Vim9: import cannot be used after method.
Solution: Recognize an imported function name. (closes https://github.com/vim/vim/issues/9496)

Change Summary

Modification

diff -r 77a4efb391c0 -r 648a5f658990 src/eval.c
--- a/src/eval.c Sat Jan 15 20:00:04 2022 +0100
+++ b/src/eval.c Sat Jan 15 22:15:03 2022 +0100
@@ -3949,7 +3949,7 @@
39493949 long len;
39503950 char_u *alias;
39513951 typval_T base = *rettv;
3952- int ret;
3952+ int ret = OK;
39533953 int evaluate = evalarg != NULL
39543954 && (evalarg->eval_flags & EVAL_EVALUATE);
39553955
@@ -3968,22 +3968,87 @@
39683968 }
39693969 else
39703970 {
3971- *arg = skipwhite(*arg);
3972- if (**arg != '(')
3971+ if (**arg == '.')
39733972 {
3974- if (verbose)
3975- semsg(_(e_missing_parenthesis_str), name);
3976- ret = FAIL;
3973+ int len2;
3974+ char_u *fname;
3975+ int idx;
3976+ imported_T *import = find_imported(name, len,
3977+ TRUE, evalarg->eval_cctx);
3978+ type_T *type;
3979+
3980+ // value->import.func()
3981+ if (import != NULL)
3982+ {
3983+ name = NULL;
3984+ ++*arg;
3985+ fname = *arg;
3986+ len2 = get_name_len(arg, &alias, evaluate, TRUE);
3987+ if (len2 <= 0)
3988+ {
3989+ emsg(_(e_missing_name_after_dot));
3990+ ret = FAIL;
3991+ }
3992+ else
3993+ {
3994+ int cc = fname[len2];
3995+ ufunc_T *ufunc;
3996+
3997+ fname[len2] = NUL;
3998+ idx = find_exported(import->imp_sid, fname, &ufunc, &type,
3999+ evalarg->eval_cctx, verbose);
4000+ fname[len2] = cc;
4001+
4002+ if (idx >= 0)
4003+ {
4004+ scriptitem_T *si = SCRIPT_ITEM(import->imp_sid);
4005+ svar_T *sv =
4006+ ((svar_T *)si->sn_var_vals.ga_data) + idx;
4007+
4008+ if (sv->sv_tv->v_type == VAR_FUNC
4009+ && sv->sv_tv->vval.v_string != NULL)
4010+ {
4011+ name = sv->sv_tv->vval.v_string;
4012+ len = STRLEN(name);
4013+ }
4014+ else
4015+ {
4016+ // TODO: how about a partial?
4017+ semsg(_(e_not_callable_type_str), fname);
4018+ ret = FAIL;
4019+ }
4020+ }
4021+ else if (ufunc != NULL)
4022+ {
4023+ name = ufunc->uf_name;
4024+ len = STRLEN(name);
4025+ }
4026+ else
4027+ ret = FAIL;
4028+ }
4029+ }
39774030 }
3978- else if (VIM_ISWHITE((*arg)[-1]))
4031+
4032+ if (ret == OK)
39794033 {
3980- if (verbose)
3981- emsg(_(e_no_white_space_allowed_before_parenthesis));
3982- ret = FAIL;
4034+ *arg = skipwhite(*arg);
4035+
4036+ if (**arg != '(')
4037+ {
4038+ if (verbose)
4039+ semsg(_(e_missing_parenthesis_str), name);
4040+ ret = FAIL;
4041+ }
4042+ else if (VIM_ISWHITE((*arg)[-1]))
4043+ {
4044+ if (verbose)
4045+ emsg(_(e_no_white_space_allowed_before_parenthesis));
4046+ ret = FAIL;
4047+ }
4048+ else
4049+ ret = eval_func(arg, evalarg, name, len, rettv,
4050+ evaluate ? EVAL_EVALUATE : 0, &base);
39834051 }
3984- else
3985- ret = eval_func(arg, evalarg, name, len, rettv,
3986- evaluate ? EVAL_EVALUATE : 0, &base);
39874052 }
39884053
39894054 // Clear the funcref afterwards, so that deleting it while
diff -r 77a4efb391c0 -r 648a5f658990 src/testdir/test_vim9_import.vim
--- a/src/testdir/test_vim9_import.vim Sat Jan 15 20:00:04 2022 +0100
+++ b/src/testdir/test_vim9_import.vim Sat Jan 15 22:15:03 2022 +0100
@@ -27,6 +27,10 @@
2727 exported += 5
2828 enddef
2929 export final theList = [1]
30+ export def AddSome(s: string): string
31+ return s .. 'some'
32+ enddef
33+ export var AddRef = AddSome
3034 END
3135
3236 def Undo_export_script_lines()
@@ -70,6 +74,9 @@
7074
7175 expo.theList->add(2)
7276 assert_equal([1, 2], expo.theList)
77+
78+ assert_equal('andthensome', 'andthen'->expo.AddSome())
79+ assert_equal('awesome', 'awe'->expo.AddRef())
7380 END
7481 writefile(import_script_lines, 'Ximport.vim')
7582 source Ximport.vim
diff -r 77a4efb391c0 -r 648a5f658990 src/version.c
--- a/src/version.c Sat Jan 15 20:00:04 2022 +0100
+++ b/src/version.c Sat Jan 15 22:15:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4102,
755+/**/
754756 4101,
755757 /**/
756758 4100,
Afficher sur ancien navigateur de dépôt.