Mercurial > vim
diff src/testdir/test_vim9_script.vim @ 23330:e8eb4fd44902 v8.2.2208
patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Commit: https://github.com/vim/vim/commit/4aab88d919168ce2ddf4845482f4cff9efa52b5b
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 24 21:56:41 2020 +0100
patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Problem: Vim9: after reloading a script variable index may be invalid.
Solution: When the sequence number doesn't match give an error for using a
script-local variable from a compiled function. (closes #7547)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Dec 2020 22:00:04 +0100 |
parents | 65fd662b434d |
children | 13572a262b15 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -3126,6 +3126,67 @@ def Test_white_space_after_command() CheckDefAndScriptFailure(lines, 'E1144:', 1) enddef +def Test_script_var_gone_when_sourced_twice() + var lines =<< trim END + vim9script + if exists('g:guard') + finish + endif + g:guard = 1 + var name = 'thename' + def g:GetName(): string + return name + enddef + def g:SetName(arg: string) + name = arg + enddef + END + writefile(lines, 'XscriptTwice.vim') + so XscriptTwice.vim + assert_equal('thename', g:GetName()) + g:SetName('newname') + assert_equal('newname', g:GetName()) + so XscriptTwice.vim + assert_fails('call g:GetName()', 'E1149:') + assert_fails('call g:SetName("x")', 'E1149:') + + delfunc g:GetName + delfunc g:SetName + delete('XscriptTwice.vim') + unlet g:guard +enddef + +def Test_import_gone_when_sourced_twice() + var exportlines =<< trim END + vim9script + if exists('g:guard') + finish + endif + g:guard = 1 + export var name = 'someName' + END + writefile(exportlines, 'XexportScript.vim') + + var lines =<< trim END + vim9script + import name from './XexportScript.vim' + def g:GetName(): string + return name + enddef + END + writefile(lines, 'XscriptImport.vim') + so XscriptImport.vim + assert_equal('someName', g:GetName()) + + so XexportScript.vim + assert_fails('call g:GetName()', 'E1149:') + + delfunc g:GetName + delete('XexportScript.vim') + delete('XscriptImport.vim') + unlet g:guard +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new