Mercurial > vim
comparison src/evalfunc.c @ 27295:69aa20a6e7ae v8.2.4176
patch 8.2.4176: Vim9: cannot use imported function with call()
Commit: https://github.com/vim/vim/commit/3d8e25a6d2660432df033cdad29f981ffe6ae0fc
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 22 11:00:02 2022 +0000
patch 8.2.4176: Vim9: cannot use imported function with call()
Problem: Vim9: cannot use imported function with call().
Solution: Translate the function name. (closes https://github.com/vim/vim/issues/9590)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 22 Jan 2022 12:15:03 +0100 |
parents | e91b577be192 |
children | ec2ba9acec1b |
comparison
equal
deleted
inserted
replaced
27294:2091a9dc5ee0 | 27295:69aa20a6e7ae |
---|---|
2927 f_call(typval_T *argvars, typval_T *rettv) | 2927 f_call(typval_T *argvars, typval_T *rettv) |
2928 { | 2928 { |
2929 char_u *func; | 2929 char_u *func; |
2930 partial_T *partial = NULL; | 2930 partial_T *partial = NULL; |
2931 dict_T *selfdict = NULL; | 2931 dict_T *selfdict = NULL; |
2932 char_u *dot; | |
2933 char_u *tofree = NULL; | |
2932 | 2934 |
2933 if (in_vim9script() | 2935 if (in_vim9script() |
2934 && (check_for_string_or_func_arg(argvars, 0) == FAIL | 2936 && (check_for_string_or_func_arg(argvars, 0) == FAIL |
2935 || check_for_list_arg(argvars, 1) == FAIL | 2937 || check_for_list_arg(argvars, 1) == FAIL |
2936 || check_for_opt_dict_arg(argvars, 2) == FAIL)) | 2938 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
2953 } | 2955 } |
2954 else | 2956 else |
2955 func = tv_get_string(&argvars[0]); | 2957 func = tv_get_string(&argvars[0]); |
2956 if (func == NULL || *func == NUL) | 2958 if (func == NULL || *func == NUL) |
2957 return; // type error, empty name or null function | 2959 return; // type error, empty name or null function |
2960 | |
2961 dot = vim_strchr(func, '.'); | |
2962 if (dot != NULL) | |
2963 { | |
2964 imported_T *import = find_imported(func, dot - func, TRUE, NULL); | |
2965 | |
2966 if (import != NULL && SCRIPT_ID_VALID(import->imp_sid)) | |
2967 { | |
2968 scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); | |
2969 | |
2970 if (si->sn_autoload_prefix != NULL) | |
2971 { | |
2972 // Turn "import.Func" into "scriptname#Func". | |
2973 tofree = concat_str(si->sn_autoload_prefix, dot + 1); | |
2974 if (tofree == NULL) | |
2975 return; | |
2976 func = tofree; | |
2977 } | |
2978 } | |
2979 } | |
2958 | 2980 |
2959 if (argvars[2].v_type != VAR_UNKNOWN) | 2981 if (argvars[2].v_type != VAR_UNKNOWN) |
2960 { | 2982 { |
2961 if (argvars[2].v_type != VAR_DICT) | 2983 if (argvars[2].v_type != VAR_DICT) |
2962 { | 2984 { |
2965 } | 2987 } |
2966 selfdict = argvars[2].vval.v_dict; | 2988 selfdict = argvars[2].vval.v_dict; |
2967 } | 2989 } |
2968 | 2990 |
2969 (void)func_call(func, &argvars[1], partial, selfdict, rettv); | 2991 (void)func_call(func, &argvars[1], partial, selfdict, rettv); |
2992 | |
2993 vim_free(tofree); | |
2970 } | 2994 } |
2971 | 2995 |
2972 /* | 2996 /* |
2973 * "changenr()" function | 2997 * "changenr()" function |
2974 */ | 2998 */ |