Mirror of the Vim source from https://github.com/vim/vim
Révision | 648a5f6589904ee2a015223fd567dfeef197f2bb (tree) |
---|---|
l'heure | 2022-01-16 06:15:03 |
Auteur | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -3949,7 +3949,7 @@ | ||
3949 | 3949 | long len; |
3950 | 3950 | char_u *alias; |
3951 | 3951 | typval_T base = *rettv; |
3952 | - int ret; | |
3952 | + int ret = OK; | |
3953 | 3953 | int evaluate = evalarg != NULL |
3954 | 3954 | && (evalarg->eval_flags & EVAL_EVALUATE); |
3955 | 3955 |
@@ -3968,22 +3968,87 @@ | ||
3968 | 3968 | } |
3969 | 3969 | else |
3970 | 3970 | { |
3971 | - *arg = skipwhite(*arg); | |
3972 | - if (**arg != '(') | |
3971 | + if (**arg == '.') | |
3973 | 3972 | { |
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 | + } | |
3977 | 4030 | } |
3978 | - else if (VIM_ISWHITE((*arg)[-1])) | |
4031 | + | |
4032 | + if (ret == OK) | |
3979 | 4033 | { |
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); | |
3983 | 4051 | } |
3984 | - else | |
3985 | - ret = eval_func(arg, evalarg, name, len, rettv, | |
3986 | - evaluate ? EVAL_EVALUATE : 0, &base); | |
3987 | 4052 | } |
3988 | 4053 | |
3989 | 4054 | // Clear the funcref afterwards, so that deleting it while |
@@ -27,6 +27,10 @@ | ||
27 | 27 | exported += 5 |
28 | 28 | enddef |
29 | 29 | export final theList = [1] |
30 | + export def AddSome(s: string): string | |
31 | + return s .. 'some' | |
32 | + enddef | |
33 | + export var AddRef = AddSome | |
30 | 34 | END |
31 | 35 | |
32 | 36 | def Undo_export_script_lines() |
@@ -70,6 +74,9 @@ | ||
70 | 74 | |
71 | 75 | expo.theList->add(2) |
72 | 76 | assert_equal([1, 2], expo.theList) |
77 | + | |
78 | + assert_equal('andthensome', 'andthen'->expo.AddSome()) | |
79 | + assert_equal('awesome', 'awe'->expo.AddRef()) | |
73 | 80 | END |
74 | 81 | writefile(import_script_lines, 'Ximport.vim') |
75 | 82 | source Ximport.vim |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 4102, | |
755 | +/**/ | |
754 | 756 | 4101, |
755 | 757 | /**/ |
756 | 758 | 4100, |