comparison src/vim9expr.c @ 27217:facb54d20a50 v8.2.4137

patch 8.2.4137: Vim9: calling import with and without method is inconsistent Commit: https://github.com/vim/vim/commit/d02dce2bb572f0e6b4570442e9cdbed14ef41820 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 18 17:43:04 2022 +0000 patch 8.2.4137: Vim9: calling import with and without method is inconsistent Problem: Vim9: calling import with and without method is inconsistent. Solution: Set a flag that a parenthsis follows to compile_load_scriptvar(). Add some more tests. Improve error message.
author Bram Moolenaar <Bram@vim.org>
date Tue, 18 Jan 2022 18:45:02 +0100
parents 63f8dbcf6a74
children 6b80d4acac8e
comparison
equal deleted inserted replaced
27216:da41f5bae90e 27217:facb54d20a50
18 18
19 // When not generating protos this is included in proto.h 19 // When not generating protos this is included in proto.h
20 #ifdef PROTO 20 #ifdef PROTO
21 # include "vim9.h" 21 # include "vim9.h"
22 #endif 22 #endif
23
24 // flag passed from compile_subscript() to compile_load_scriptvar()
25 static int paren_follows_after_expr = 0;
23 26
24 /* 27 /*
25 * Generate code for any ppconst entries. 28 * Generate code for any ppconst entries.
26 */ 29 */
27 int 30 int
275 ufunc_T *ufunc; 278 ufunc_T *ufunc;
276 type_T *type; 279 type_T *type;
277 int done = FALSE; 280 int done = FALSE;
278 int res = OK; 281 int res = OK;
279 282
280 // TODO: if this is an autoload import do something else.
281 // Need to lookup the member. 283 // Need to lookup the member.
282 if (*p != '.') 284 if (*p != '.')
283 { 285 {
284 semsg(_(e_expected_dot_after_name_str), start); 286 semsg(_(e_expected_dot_after_name_str), start);
285 return FAIL; 287 return FAIL;
304 { 306 {
305 char_u *auto_name = concat_str(si->sn_autoload_prefix, exp_name); 307 char_u *auto_name = concat_str(si->sn_autoload_prefix, exp_name);
306 308
307 // autoload script must be loaded later, access by the autoload 309 // autoload script must be loaded later, access by the autoload
308 // name. 310 // name.
309 if (cc == '(') 311 if (cc == '(' || paren_follows_after_expr)
310 res = generate_PUSHFUNC(cctx, auto_name, &t_func_any); 312 res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
311 else 313 else
312 res = generate_LOAD(cctx, ISN_LOADG, 0, auto_name, &t_any); 314 res = generate_LOAD(cctx, ISN_LOADG, 0, auto_name, &t_any);
313 vim_free(auto_name); 315 vim_free(auto_name);
314 done = TRUE; 316 done = TRUE;
1734 { 1736 {
1735 int fail; 1737 int fail;
1736 int save_len = cctx->ctx_ufunc->uf_lines.ga_len; 1738 int save_len = cctx->ctx_ufunc->uf_lines.ga_len;
1737 1739
1738 *paren = NUL; 1740 *paren = NUL;
1741
1742 // instead of using LOADG for "import.Func" use PUSHFUNC
1743 ++paren_follows_after_expr;
1744
1739 // do not look in the next line 1745 // do not look in the next line
1740 cctx->ctx_ufunc->uf_lines.ga_len = 1; 1746 cctx->ctx_ufunc->uf_lines.ga_len = 1;
1747
1741 fail = compile_expr8(arg, cctx, ppconst) == FAIL 1748 fail = compile_expr8(arg, cctx, ppconst) == FAIL
1742 || *skipwhite(*arg) != NUL; 1749 || *skipwhite(*arg) != NUL;
1743 *paren = '('; 1750 *paren = '(';
1751 --paren_follows_after_expr;
1744 cctx->ctx_ufunc->uf_lines.ga_len = save_len; 1752 cctx->ctx_ufunc->uf_lines.ga_len = save_len;
1753
1745 if (fail) 1754 if (fail)
1746 { 1755 {
1747 semsg(_(e_invalid_expression_str), pstart); 1756 semsg(_(e_invalid_expression_str), pstart);
1748 return FAIL; 1757 return FAIL;
1749 } 1758 }