Mercurial > vim
comparison src/evalvars.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 | 69a48bcd1d80 |
children | f00a7a2bee21 |
comparison
equal
deleted
inserted
replaced
27463:c50f682d1183 | 27464:a14c4d3e3260 |
---|---|
2777 found = TRUE; | 2777 found = TRUE; |
2778 } | 2778 } |
2779 } | 2779 } |
2780 else if (in_vim9script() && (flags & EVAL_VAR_NO_FUNC) == 0) | 2780 else if (in_vim9script() && (flags & EVAL_VAR_NO_FUNC) == 0) |
2781 { | 2781 { |
2782 int has_g_prefix = STRNCMP(name, "g:", 2) == 0; | |
2782 ufunc_T *ufunc = find_func(name, FALSE); | 2783 ufunc_T *ufunc = find_func(name, FALSE); |
2783 | 2784 |
2784 // In Vim9 script we can get a function reference by using the | 2785 // In Vim9 script we can get a function reference by using the |
2785 // function name. | 2786 // function name. For a global non-autoload function "g:" is |
2786 if (ufunc != NULL) | 2787 // required. |
2788 if (ufunc != NULL && (has_g_prefix | |
2789 || !func_requires_g_prefix(ufunc))) | |
2787 { | 2790 { |
2788 found = TRUE; | 2791 found = TRUE; |
2789 if (rettv != NULL) | 2792 if (rettv != NULL) |
2790 { | 2793 { |
2791 rettv->v_type = VAR_FUNC; | 2794 rettv->v_type = VAR_FUNC; |
2792 if (STRNCMP(name, "g:", 2) == 0) | 2795 if (has_g_prefix) |
2793 // Keep the "g:", otherwise script-local may be | 2796 // Keep the "g:", otherwise script-local may be |
2794 // assumed. | 2797 // assumed. |
2795 rettv->vval.v_string = vim_strsave(name); | 2798 rettv->vval.v_string = vim_strsave(name); |
2796 else | 2799 else |
2797 rettv->vval.v_string = vim_strsave(ufunc->uf_name); | 2800 rettv->vval.v_string = vim_strsave(ufunc->uf_name); |