comparison 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
comparison
equal deleted inserted replaced
23329:2d0d83f002e8 23330:e8eb4fd44902
3124 exit_cb: Func}) 3124 exit_cb: Func})
3125 END 3125 END
3126 CheckDefAndScriptFailure(lines, 'E1144:', 1) 3126 CheckDefAndScriptFailure(lines, 'E1144:', 1)
3127 enddef 3127 enddef
3128 3128
3129 def Test_script_var_gone_when_sourced_twice()
3130 var lines =<< trim END
3131 vim9script
3132 if exists('g:guard')
3133 finish
3134 endif
3135 g:guard = 1
3136 var name = 'thename'
3137 def g:GetName(): string
3138 return name
3139 enddef
3140 def g:SetName(arg: string)
3141 name = arg
3142 enddef
3143 END
3144 writefile(lines, 'XscriptTwice.vim')
3145 so XscriptTwice.vim
3146 assert_equal('thename', g:GetName())
3147 g:SetName('newname')
3148 assert_equal('newname', g:GetName())
3149 so XscriptTwice.vim
3150 assert_fails('call g:GetName()', 'E1149:')
3151 assert_fails('call g:SetName("x")', 'E1149:')
3152
3153 delfunc g:GetName
3154 delfunc g:SetName
3155 delete('XscriptTwice.vim')
3156 unlet g:guard
3157 enddef
3158
3159 def Test_import_gone_when_sourced_twice()
3160 var exportlines =<< trim END
3161 vim9script
3162 if exists('g:guard')
3163 finish
3164 endif
3165 g:guard = 1
3166 export var name = 'someName'
3167 END
3168 writefile(exportlines, 'XexportScript.vim')
3169
3170 var lines =<< trim END
3171 vim9script
3172 import name from './XexportScript.vim'
3173 def g:GetName(): string
3174 return name
3175 enddef
3176 END
3177 writefile(lines, 'XscriptImport.vim')
3178 so XscriptImport.vim
3179 assert_equal('someName', g:GetName())
3180
3181 so XexportScript.vim
3182 assert_fails('call g:GetName()', 'E1149:')
3183
3184 delfunc g:GetName
3185 delete('XexportScript.vim')
3186 delete('XscriptImport.vim')
3187 unlet g:guard
3188 enddef
3189
3129 " Keep this last, it messes up highlighting. 3190 " Keep this last, it messes up highlighting.
3130 def Test_substitute_cmd() 3191 def Test_substitute_cmd()
3131 new 3192 new
3132 setline(1, 'something') 3193 setline(1, 'something')
3133 :substitute(some(other( 3194 :substitute(some(other(