Mercurial > vim
comparison src/userfunc.c @ 21699:1b96535705a0 v8.2.1399
patch 8.2.1399: Vim9: may find imported item in wrong script
Commit: https://github.com/vim/vim/commit/efa94447e85eacce62c1fcf6b63e7f3431e2cb1b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 8 22:16:00 2020 +0200
patch 8.2.1399: Vim9: may find imported item in wrong script
Problem: Vim9: may find imported item in wrong script.
Solution: When looking up script-local function use the embedded script ID.
(issue #6644)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 08 Aug 2020 22:30:03 +0200 |
parents | 26a4b53c4587 |
children | a849c984b485 |
comparison
equal
deleted
inserted
replaced
21698:df2188073dca | 21699:1b96535705a0 |
---|---|
789 | 789 |
790 if (!is_global) | 790 if (!is_global) |
791 { | 791 { |
792 int vim9script = in_vim9script(); | 792 int vim9script = in_vim9script(); |
793 char_u *after_script = NULL; | 793 char_u *after_script = NULL; |
794 long sid = 0; | |
794 | 795 |
795 if (vim9script) | 796 if (vim9script) |
796 { | 797 { |
797 // Find script-local function before global one. | 798 // Find script-local function before global one. |
798 func = find_func_with_sid(name, current_sctx.sc_sid); | 799 func = find_func_with_sid(name, current_sctx.sc_sid); |
799 if (func != NULL) | 800 if (func != NULL) |
800 return func; | 801 return func; |
801 } | 802 } |
802 | 803 |
803 if (!vim9script | 804 if (name[0] == K_SPECIAL |
804 && name[0] == K_SPECIAL | |
805 && name[1] == KS_EXTRA | 805 && name[1] == KS_EXTRA |
806 && name[2] == KE_SNR) | 806 && name[2] == KE_SNR) |
807 { | 807 { |
808 long sid; | |
809 | |
810 // Caller changes s: to <SNR>99_name. | 808 // Caller changes s: to <SNR>99_name. |
811 | 809 |
812 after_script = name + 3; | 810 after_script = name + 3; |
813 sid = getdigits(&after_script); | 811 sid = getdigits(&after_script); |
814 if (sid == current_sctx.sc_sid && *after_script == '_') | 812 if (*after_script == '_') |
815 ++after_script; | 813 ++after_script; |
816 else | 814 else |
817 after_script = NULL; | 815 after_script = NULL; |
818 } | 816 } |
819 if (vim9script || after_script != NULL) | 817 if (vim9script || after_script != NULL) |
820 { | 818 { |
821 // Find imported function before global one. | 819 // Find imported function before global one. |
822 imported = find_imported( | 820 if (after_script != NULL && sid != current_sctx.sc_sid) |
823 after_script == NULL ? name : after_script, 0, cctx); | 821 imported = find_imported_in_script(after_script, 0, sid); |
822 else | |
823 imported = find_imported(after_script == NULL | |
824 ? name : after_script, 0, cctx); | |
824 if (imported != NULL && imported->imp_funcname != NULL) | 825 if (imported != NULL && imported->imp_funcname != NULL) |
825 { | 826 { |
826 hi = hash_find(&func_hashtab, imported->imp_funcname); | 827 hi = hash_find(&func_hashtab, imported->imp_funcname); |
827 if (!HASHITEM_EMPTY(hi)) | 828 if (!HASHITEM_EMPTY(hi)) |
828 return HI2UF(hi); | 829 return HI2UF(hi); |