Skip to content

Commit

Permalink
patch 8.2.4184: cannot use an import in 'includeexpr'
Browse files Browse the repository at this point in the history
Problem:    Cannot use an import in 'includeexpr'.
Solution:   Set the script context when evaluating 'includeexpr'
  • Loading branch information
brammool committed Jan 22, 2022
1 parent 3ba685e commit 47bcc5f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/findfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,11 +2094,16 @@ file_name_in_line(
eval_includeexpr(char_u *ptr, int len)
{
char_u *res;
sctx_T save_sctx = current_sctx;

set_vim_var_string(VV_FNAME, ptr, len);
current_sctx = curbuf->b_p_script_ctx[BV_INEX];

res = eval_to_string_safe(curbuf->b_p_inex,
was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), FALSE);
was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), TRUE);

set_vim_var_string(VV_FNAME, NULL, 0);
current_sctx = save_sctx;
return res;
}
# endif
Expand Down
30 changes: 30 additions & 0 deletions src/testdir/test_vim9_import.vim
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,36 @@ def Test_import_in_formatexpr()
set formatexpr=
enddef

def Test_import_in_includeexpr()
writefile(['found it'], 'Xthisfile')
new

var lines =<< trim END
vim9script
export def DoSub(): string
return substitute(v:fname, 'that', 'this', '')
enddef
END
writefile(lines, 'Xinclude.vim')

lines =<< trim END
vim9script
import './Xinclude.vim'
set includeexpr=Xinclude.DoSub()
END
CheckScriptSuccess(lines)

setline(1, ['Xthatfile'])
exe "normal \<C-W>f"
assert_equal('Xthisfile', expand('%'))

bwipe!
bwipe!
set includeexpr=
delete('Xinclude')
delete('Xthisfile')
enddef

def Test_export_fails()
CheckScriptFailure(['export var some = 123'], 'E1042:')
CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4184,
/**/
4183,
/**/
Expand Down

0 comments on commit 47bcc5f

Please sign in to comment.