diff --git a/src/scriptfile.c b/src/scriptfile.c index 5c2c2b3bae..4b9c5c75fd 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1663,6 +1663,7 @@ do_source_ext( int sid = -1; scriptitem_T *si = NULL; int save_estack_compiling = estack_compiling; + int save_is_export = is_export; ESTACK_CHECK_DECLARATION; #endif @@ -1690,6 +1691,10 @@ do_source_ext( } #ifdef FEAT_EVAL estack_compiling = FALSE; + // An ":export" command may source the script, e.g. for an autoload + // import used in its value. That does not export what the script + // defines. + is_export = FALSE; // See if we loaded this script before. sid = find_script_by_name(fname_exp); @@ -2089,6 +2094,7 @@ theend: sticky_cmdmod_flags = save_sticky_cmdmod_flags; #ifdef FEAT_EVAL estack_compiling = save_estack_compiling; + is_export = save_is_export; #endif return retval; } diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index 4c441b1ca3..0bb8906f78 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -3454,6 +3454,34 @@ def Test_imported_class_as_def_func_rettype() v9.CheckScriptSuccess(lines) enddef +" Test for an autoload script sourced for the value of an exported variable +def Test_export_value_sources_autoload_script() + for kind in ['var', 'const', 'final'] + var lines =<< trim END + vim9script + export const VALUE = 42 + export def Get(): number + return 7 + enddef + END + writefile(lines, $'Xexportvalue_{kind}1.vim', 'D') + + lines =<< eval trim END + vim9script + import autoload './Xexportvalue_{kind}1.vim' as A + export {kind} x = A.VALUE + A.Get() + END + writefile(lines, $'Xexportvalue_{kind}2.vim', 'D') + + lines =<< eval trim END + vim9script + import './Xexportvalue_{kind}2.vim' as B + assert_equal(49, B.x) + END + v9.CheckScriptSuccess(lines) + endfor +enddef + " Test for don't crash when using a combination of import and class extends def Test_vim9_import_and_class_extends() var lines =<< trim END diff --git a/src/userfunc.c b/src/userfunc.c index 8ef03cf9ec..fbc3cc2783 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -5680,19 +5680,11 @@ define_function( // The function may use script variables from the context. function_using_block_scopes(fp, cstack); - // The argument types and the return type may use an imported type. - // In that case, the imported file will be sourced. To avoid treating - // everything in the imported file as exported, temporarily reset - // is_export. - int save_is_export = is_export; - is_export = FALSE; - if (parse_argument_types(fp, &argtypes, varargs, &arg_objm, obj_members, obj_member_count, cctx) == FAIL) { SOURCING_LNUM = lnum_save; free_fp = fp_allocated; - is_export = save_is_export; goto erret; } varargs = FALSE; @@ -5702,10 +5694,8 @@ define_function( { SOURCING_LNUM = lnum_save; free_fp = fp_allocated; - is_export = save_is_export; goto erret; } - is_export = save_is_export; SOURCING_LNUM = lnum_save; } else diff --git a/src/version.c b/src/version.c index 61aad38ed6..a88cd1dc8f 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1252, /**/ 1251, /**/