diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-01-12 11:46:40 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-01-12 11:46:40 +0000 |
commit | 17d36cbcd36d944c744ef68afa971718959b2111 (patch) | |
tree | 6b9499d690e2ceddf00106997569ee2e5643b0a8 | |
parent | 3cf21b305104e91a28e4ce3a473672b2e88a9469 (diff) |
patch 8.2.4066: Vim9: imported autoload script loaded againv8.2.4066
Problem: Vim9: imported autoload script loaded again.
Solution: Do not create a new imported_T every time.
-rw-r--r-- | src/testdir/test_vim9_import.vim | 11 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 4 | ||||
-rw-r--r-- | src/vim9script.c | 25 |
4 files changed, 29 insertions, 13 deletions
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index 46b826c949..7aa1549155 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -1140,7 +1140,7 @@ def Test_vim9script_autoload() # when using "vim9script autoload" prefix is not needed var lines =<< trim END vim9script autoload - g:prefixed_loaded = 'yes' + g:prefixed_loaded += 1 export def Gettest(): string return 'test' @@ -1156,12 +1156,14 @@ def Test_vim9script_autoload() END writefile(lines, 'Xdir/autoload/prefixed.vim') + g:prefixed_loaded = 0 + g:expected_loaded = 0 lines =<< trim END vim9script import autoload 'prefixed.vim' - assert_false(exists('g:prefixed_loaded')) + assert_equal(g:expected_loaded, g:prefixed_loaded) assert_equal('test', prefixed.Gettest()) - assert_equal('yes', g:prefixed_loaded) + assert_equal(1, g:prefixed_loaded) assert_equal('testmore', prefixed.GetMore()) assert_equal('name', prefixed.name) @@ -1169,6 +1171,9 @@ def Test_vim9script_autoload() assert_equal('const', prefixed.cname) END CheckScriptSuccess(lines) + # can source it again, autoload script not loaded again + g:expected_loaded = 1 + CheckScriptSuccess(lines) # can also get the items by autoload name lines =<< trim END diff --git a/src/version.c b/src/version.c index e329775342..24d2f087d3 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4066, +/**/ 4065, /**/ 4064, diff --git a/src/vim9compile.c b/src/vim9compile.c index 963c052006..90cb2b4ffa 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -623,10 +623,12 @@ find_imported(char_u *name, size_t len, int load, cctx_T *cctx) if (ret != NULL && load && ret->imp_flags == IMP_FLAGS_AUTOLOAD) { + scid_T dummy; + // script found before but not loaded yet ret->imp_flags = 0; (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE, - DOSO_NONE, NULL); + DOSO_NONE, &dummy); } return ret; } diff --git a/src/vim9script.c b/src/vim9script.c index d3e1922405..b72995c11c 100644 --- a/src/vim9script.c +++ b/src/vim9script.c @@ -250,6 +250,8 @@ ex_incdec(exarg_T *eap) void ex_export(exarg_T *eap) { + int prev_did_emsg = did_emsg; + if (!in_vim9script()) { emsg(_(e_export_can_only_be_used_in_vim9script)); @@ -273,12 +275,14 @@ ex_export(exarg_T *eap) // The command will reset "is_export" when exporting an item. if (is_export) { - emsg(_(e_export_with_invalid_argument)); + if (did_emsg == prev_did_emsg) + emsg(_(e_export_with_invalid_argument)); is_export = FALSE; } break; default: - emsg(_(e_invalid_command_after_export)); + if (did_emsg == prev_did_emsg) + emsg(_(e_invalid_command_after_export)); break; } } @@ -589,14 +593,17 @@ handle_import( && check_defined(as_name, STRLEN(as_name), cctx, FALSE) == FAIL) goto erret; - imported = new_imported(import_gap); if (imported == NULL) - goto erret; - imported->imp_name = as_name; - as_name = NULL; - imported->imp_sid = sid; - if (is_autoload) - imported->imp_flags = IMP_FLAGS_AUTOLOAD; + { + imported = new_imported(import_gap); + if (imported == NULL) + goto erret; + imported->imp_name = as_name; + as_name = NULL; + imported->imp_sid = sid; + if (is_autoload) + imported->imp_flags = IMP_FLAGS_AUTOLOAD; + } } erret: |