Patch 8.2.4066
Problem: Vim9: imported autoload script loaded again.
Solution: Do not create a new imported_T every time.
Files: src/vim9script.c, src/vim9compile.c,
src/testdir/test_vim9_import.vim
*** ../vim-8.2.4065/src/vim9script.c 2022-01-10 21:29:53.380429159 +0000
--- src/vim9script.c 2022-01-12 10:25:00.628367892 +0000
***************
*** 250,255 ****
--- 250,257 ----
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,284 ****
// The command will reset "is_export" when exporting an item.
if (is_export)
{
! emsg(_(e_export_with_invalid_argument));
is_export = FALSE;
}
break;
default:
! emsg(_(e_invalid_command_after_export));
break;
}
}
--- 275,288 ----
// The command will reset "is_export" when exporting an item.
if (is_export)
{
! if (did_emsg == prev_did_emsg)
! emsg(_(e_export_with_invalid_argument));
is_export = FALSE;
}
break;
default:
! if (did_emsg == prev_did_emsg)
! emsg(_(e_invalid_command_after_export));
break;
}
}
***************
*** 589,602 ****
&& 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;
}
erret:
--- 593,609 ----
&& check_defined(as_name, STRLEN(as_name), cctx, FALSE) == FAIL)
goto erret;
if (imported == NULL)
! {
! 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:
*** ../vim-8.2.4065/src/vim9compile.c 2022-01-10 18:42:48.772314418 +0000
--- src/vim9compile.c 2022-01-12 11:44:01.115136906 +0000
***************
*** 623,632 ****
if (ret != NULL && load && ret->imp_flags == IMP_FLAGS_AUTOLOAD)
{
// 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);
}
return ret;
}
--- 623,634 ----
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, &dummy);
}
return ret;
}
*** ../vim-8.2.4065/src/testdir/test_vim9_import.vim 2022-01-11 15:24:01.307663435 +0000
--- src/testdir/test_vim9_import.vim 2022-01-12 11:38:51.572167619 +0000
***************
*** 1140,1146 ****
# when using "vim9script autoload" prefix is not needed
var lines =<< trim END
vim9script autoload
! g:prefixed_loaded = 'yes'
export def Gettest(): string
return 'test'
--- 1140,1146 ----
# when using "vim9script autoload" prefix is not needed
var lines =<< trim END
vim9script autoload
! g:prefixed_loaded += 1
export def Gettest(): string
return 'test'
***************
*** 1156,1167 ****
END
writefile(lines, 'Xdir/autoload/prefixed.vim')
lines =<< trim END
vim9script
import autoload 'prefixed.vim'
! assert_false(exists('g:prefixed_loaded'))
assert_equal('test', prefixed.Gettest())
! assert_equal('yes', g:prefixed_loaded)
assert_equal('testmore', prefixed.GetMore())
assert_equal('name',
prefixed.name)
--- 1156,1169 ----
END
writefile(lines, 'Xdir/autoload/prefixed.vim')
+ g:prefixed_loaded = 0
+ g:expected_loaded = 0
lines =<< trim END
vim9script
import autoload 'prefixed.vim'
! assert_equal(g:expected_loaded, g:prefixed_loaded)
assert_equal('test', prefixed.Gettest())
! assert_equal(1, g:prefixed_loaded)
assert_equal('testmore', prefixed.GetMore())
assert_equal('name',
prefixed.name)
***************
*** 1169,1174 ****
--- 1171,1179 ----
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
*** ../vim-8.2.4065/src/version.c 2022-01-11 19:34:12.449500357 +0000
--- src/version.c 2022-01-12 10:26:29.424087465 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4066,
/**/
--
If I tell you "you have a beautiful body", would you hold it against me?
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///