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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user