comparison src/vim9compile.c @ 24124:f4061617c438 v8.2.2603

patch 8.2.2603: Vim9: no effect if user command is also a function Commit: https://github.com/vim/vim/commit/77b10ffad4ebad15022614be4db2745f6a90f405 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 14 13:21:35 2021 +0100 patch 8.2.2603: Vim9: no effect if user command is also a function Problem: Vim9: no effect if user command is also a function. Solution: Check for paren following. (closes https://github.com/vim/vim/issues/7960)
author Bram Moolenaar <Bram@vim.org>
date Sun, 14 Mar 2021 13:30:03 +0100
parents a028cb6898a2
children c308076e225e
comparison
equal deleted inserted replaced
24123:d97cddd9f357 24124:f4061617c438
389 /* 389 /*
390 * Return TRUE if "name" is a local variable, argument, script variable, 390 * Return TRUE if "name" is a local variable, argument, script variable,
391 * imported or function. 391 * imported or function.
392 */ 392 */
393 static int 393 static int
394 item_exists(char_u *name, size_t len, cctx_T *cctx) 394 item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx)
395 { 395 {
396 int is_global; 396 int is_global;
397 char_u *p;
397 398
398 if (variable_exists(name, len, cctx)) 399 if (variable_exists(name, len, cctx))
399 return TRUE; 400 return TRUE;
400 401
401 // Find a function, so that a following "->" works. Skip "g:" before a 402 // This is similar to what is in lookup_scriptitem():
402 // function name. 403 // Find a function, so that a following "->" works.
403 // Do not check for an internal function, since it might also be a 404 // Require "(" or "->" to follow, "Cmd" is a user command while "Cmd()" is
404 // valid command, such as ":split" versuse "split()". 405 // a function call.
405 is_global = (name[0] == 'g' && name[1] == ':'); 406 p = skipwhite(name + len);
406 return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL; 407
408 if (name[len] == '(' || (p[0] == '-' && p[1] == '>'))
409 {
410 // Do not check for an internal function, since it might also be a
411 // valid command, such as ":split" versuse "split()".
412 // Skip "g:" before a function name.
413 is_global = (name[0] == 'g' && name[1] == ':');
414 return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
415 }
416 return FALSE;
407 } 417 }
408 418
409 /* 419 /*
410 * Check if "p[len]" is already defined, either in script "import_sid" or in 420 * Check if "p[len]" is already defined, either in script "import_sid" or in
411 * compilation context "cctx". "cctx" is NULL at the script level. 421 * compilation context "cctx". "cctx" is NULL at the script level.
8427 line = compile_exec(line, &ea, &cctx); 8437 line = compile_exec(line, &ea, &cctx);
8428 goto nextline; 8438 goto nextline;
8429 } 8439 }
8430 } 8440 }
8431 } 8441 }
8432 p = find_ex_command(&ea, NULL, starts_with_colon ? NULL 8442 p = find_ex_command(&ea, NULL, starts_with_colon
8433 : (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx); 8443 ? NULL : item_exists, &cctx);
8434 8444
8435 if (p == NULL) 8445 if (p == NULL)
8436 { 8446 {
8437 if (cctx.ctx_skip != SKIP_YES) 8447 if (cctx.ctx_skip != SKIP_YES)
8438 emsg(_(e_ambiguous_use_of_user_defined_command)); 8448 emsg(_(e_ambiguous_use_of_user_defined_command));