patch 9.2.1252: Vim9: autoload script sourced for an exported value fails
Problem: When the value of an exported variable sources an autoload
script, the script fails to load with E1043.
Solution: Reset is_export while sourcing a script, and remove the reset
added in patch 9.1.1040 (Hirohito Higashi)
closes: #21610
Assisted-by: Claude
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
1 parent
008d442795
commit
90d3806e39
4 files changed
+36
-10
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -743,6 +743,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1252,
|
||||
/**/
|
||||
1251,
|
||||
/**/
|
||||
|
||||
Reference in new issue
Block a user