1
0
forked from aniani/vim

patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain

Problem:    Vim9: Declarations in a {} block of a user command do not use Vim9
            rules if defined in a legacy script. (Yegappan Lakshmanan)
Solution:   Pretend the script is Vim9 script.
This commit is contained in:
Bram Moolenaar
2022-03-23 21:36:27 +00:00
parent ac48506ac6
commit 98b7fe725e
3 changed files with 58 additions and 0 deletions

View File

@@ -798,4 +798,40 @@ func Test_multibyte_in_usercmd()
delcommand SubJapanesePeriodToDot
endfunc
" Declaring a variable in a {} uses Vim9 script rules, even when defined in a
" legacy script.
func Test_block_declaration_legacy_script()
let lines =<< trim END
command -range Rename {
var save = @a
@a = 'something'
g:someExpr = @a
@a = save
}
END
call writefile(lines, 'Xlegacy')
source Xlegacy
let lines =<< trim END
let @a = 'saved'
Rename
call assert_equal('something', g:someExpr)
call assert_equal('saved', @a)
let g:someExpr = 'xxx'
let @a = 'also'
Rename
call assert_equal('something', g:someExpr)
call assert_equal('also', @a)
END
call writefile(lines, 'Xother')
source Xother
unlet g:someExpr
call delete('Xlegacy')
call delete('Xother')
delcommand Rename
endfunc
" vim: shiftwidth=2 sts=2 expandtab