Mercurial > vim
comparison src/vim9expr.c @ 27464:a14c4d3e3260 v8.2.4260
patch 8.2.4260: Vim9: can still use a global function without g:
Commit: https://github.com/vim/vim/commit/848faddb870f3ba4d84fcacd1cccb5cdbbfd9c41
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 30 15:28:30 2022 +0000
patch 8.2.4260: Vim9: can still use a global function without g:
Problem: Vim9: can still use a global function without g: at the script
level.
Solution: Also check for g: at the script level. (issue #9637)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 30 Jan 2022 16:30:04 +0100 |
parents | 4c16acb2525f |
children | 29104ffb4dca |
comparison
equal
deleted
inserted
replaced
27463:c50f682d1183 | 27464:a14c4d3e3260 |
---|---|
347 semsg(_(e_item_not_found_str), name); | 347 semsg(_(e_item_not_found_str), name); |
348 return FAIL; | 348 return FAIL; |
349 } | 349 } |
350 | 350 |
351 static int | 351 static int |
352 generate_funcref(cctx_T *cctx, char_u *name) | 352 generate_funcref(cctx_T *cctx, char_u *name, int has_g_prefix) |
353 { | 353 { |
354 ufunc_T *ufunc = find_func(name, FALSE); | 354 ufunc_T *ufunc = find_func(name, FALSE); |
355 | 355 |
356 if (ufunc == NULL) | 356 // Reject a global non-autoload function found without the "g:" prefix. |
357 if (ufunc == NULL || (!has_g_prefix && func_requires_g_prefix(ufunc))) | |
357 return FAIL; | 358 return FAIL; |
358 | 359 |
359 // Need to compile any default values to get the argument types. | 360 // Need to compile any default values to get the argument types. |
360 if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc)) | 361 if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc)) |
361 && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), NULL) | 362 && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), NULL) |
418 { | 419 { |
419 case 'v': res = generate_LOADV(cctx, name, error); | 420 case 'v': res = generate_LOADV(cctx, name, error); |
420 break; | 421 break; |
421 case 's': if (is_expr && ASCII_ISUPPER(*name) | 422 case 's': if (is_expr && ASCII_ISUPPER(*name) |
422 && find_func(name, FALSE) != NULL) | 423 && find_func(name, FALSE) != NULL) |
423 res = generate_funcref(cctx, name); | 424 res = generate_funcref(cctx, name, FALSE); |
424 else | 425 else |
425 res = compile_load_scriptvar(cctx, name, | 426 res = compile_load_scriptvar(cctx, name, |
426 NULL, &end, error); | 427 NULL, &end, error); |
427 break; | 428 break; |
428 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) | 429 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL) |
429 { | 430 { |
430 if (is_expr && ASCII_ISUPPER(*name) | 431 if (is_expr && ASCII_ISUPPER(*name) |
431 && find_func(name, FALSE) != NULL) | 432 && find_func(name, FALSE) != NULL) |
432 res = generate_funcref(cctx, name); | 433 res = generate_funcref(cctx, name, TRUE); |
433 else | 434 else |
434 isn_type = ISN_LOADG; | 435 isn_type = ISN_LOADG; |
435 } | 436 } |
436 else | 437 else |
437 { | 438 { |
503 | 504 |
504 // When evaluating an expression and the name starts with an | 505 // When evaluating an expression and the name starts with an |
505 // uppercase letter it can be a user defined function. | 506 // uppercase letter it can be a user defined function. |
506 // generate_funcref() will fail if the function can't be found. | 507 // generate_funcref() will fail if the function can't be found. |
507 if (res == FAIL && is_expr && ASCII_ISUPPER(*name)) | 508 if (res == FAIL && is_expr && ASCII_ISUPPER(*name)) |
508 res = generate_funcref(cctx, name); | 509 res = generate_funcref(cctx, name, FALSE); |
509 } | 510 } |
510 } | 511 } |
511 if (gen_load) | 512 if (gen_load) |
512 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type); | 513 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type); |
513 if (gen_load_outer > 0) | 514 if (gen_load_outer > 0) |
810 } | 811 } |
811 } | 812 } |
812 | 813 |
813 // If the name is a variable, load it and use PCALL. | 814 // If the name is a variable, load it and use PCALL. |
814 // Not for g:Func(), we don't know if it is a variable or not. | 815 // Not for g:Func(), we don't know if it is a variable or not. |
815 // Not for eome#Func(), it will be loaded later. | 816 // Not for some#Func(), it will be loaded later. |
816 p = namebuf; | 817 p = namebuf; |
817 if (!has_g_namespace && !is_autoload | 818 if (!has_g_namespace && !is_autoload |
818 && compile_load(&p, namebuf + varlen, cctx, FALSE, FALSE) == OK) | 819 && compile_load(&p, namebuf + varlen, cctx, FALSE, FALSE) == OK) |
819 { | 820 { |
820 type_T *type = get_type_on_stack(cctx, 0); | 821 type_T *type = get_type_on_stack(cctx, 0); |