Skip to content

Commit 81e17fb

Browse files
committed
patch 8.2.1503: Vim9: error for autocmd defined in :def in legacy script
Problem: Vim9: error for an autocmd defined in a :def function in legacy Vim script. Solution: Don't check the variable type. (closes #6758)
1 parent 122616d commit 81e17fb

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,23 @@ def Test_vim9_autoload()
31663166
&rtp = save_rtp
31673167
enddef
31683168

3169+
def Test_script_var_in_autocmd()
3170+
# using a script variable from an autocommand, defined in a :def function in a
3171+
# legacy Vim script, cannot check the variable type.
3172+
let lines =<< trim END
3173+
let s:counter = 1
3174+
def s:Func()
3175+
au! CursorHold
3176+
au CursorHold * s:counter += 1
3177+
enddef
3178+
call s:Func()
3179+
doau CursorHold
3180+
call assert_equal(2, s:counter)
3181+
au! CursorHold
3182+
END
3183+
CheckScriptSuccess(lines)
3184+
enddef
3185+
31693186
def Test_cmdline_win()
31703187
# if the Vim syntax highlighting uses Vim9 constructs they can be used from
31713188
# the command line window.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1503,
757759
/**/
758760
1502,
759761
/**/

src/vim9script.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
564564
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
565565
int idx;
566566

567+
if (si->sn_version != SCRIPT_VERSION_VIM9)
568+
// legacy script doesn't store variable types
569+
return OK;
570+
567571
// Find the svar_T in sn_var_vals.
568572
for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
569573
{

0 commit comments

Comments
 (0)