comparison src/testdir/test_tagfunc.vim @ 27457:4c16acb2525f v8.2.4257

patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 21:45:34 2022 +0000 patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Problem: Vim9: finding global function without g: prefix but not finding global variable is inconsistent. Solution: Require using g: for a global function. Change the vim9.vim script into a Vim9 script with exports. Fix that import in legacy script does not work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:00:05 +0100
parents b531c26f728b
children 19367412787c
comparison
equal deleted inserted replaced
27456:a8e2d91995ce 27457:4c16acb2525f
1 " Test 'tagfunc' 1 " Test 'tagfunc'
2 2
3 source vim9.vim 3 import './vim9.vim' as v9
4 source check.vim 4 source check.vim
5 source screendump.vim 5 source screendump.vim
6 6
7 func TagFunc(pat, flag, info) 7 func TagFunc(pat, flag, info)
8 let g:tagfunc_args = [a:pat, a:flag, a:info] 8 let g:tagfunc_args = [a:pat, a:flag, a:info]
198 call assert_fails('tag a14', 'E433:') 198 call assert_fails('tag a14', 'E433:')
199 call assert_equal([15, 'a14', '', {}], g:TagFunc1Args) 199 call assert_equal([15, 'a14', '', {}], g:TagFunc1Args)
200 bw! 200 bw!
201 201
202 #" Test for using a lambda function 202 #" Test for using a lambda function
203 VAR optval = "LSTART a, b, c LMIDDLE TagFunc1(16, a, b, c) LEND" 203 VAR optval = "LSTART a, b, c LMIDDLE g:TagFunc1(16, a, b, c) LEND"
204 LET optval = substitute(optval, ' ', '\\ ', 'g') 204 LET optval = substitute(optval, ' ', '\\ ', 'g')
205 exe "set tagfunc=" .. optval 205 exe "set tagfunc=" .. optval
206 new 206 new
207 LET g:TagFunc1Args = [] 207 LET g:TagFunc1Args = []
208 call assert_fails('tag a17', 'E433:') 208 call assert_fails('tag a17', 'E433:')
209 call assert_equal([16, 'a17', '', {}], g:TagFunc1Args) 209 call assert_equal([16, 'a17', '', {}], g:TagFunc1Args)
210 bw! 210 bw!
211 211
212 #" Set 'tagfunc' to a lambda expression 212 #" Set 'tagfunc' to a lambda expression
213 LET &tagfunc = LSTART a, b, c LMIDDLE TagFunc1(17, a, b, c) LEND 213 LET &tagfunc = LSTART a, b, c LMIDDLE g:TagFunc1(17, a, b, c) LEND
214 new 214 new
215 LET g:TagFunc1Args = [] 215 LET g:TagFunc1Args = []
216 call assert_fails('tag a18', 'E433:') 216 call assert_fails('tag a18', 'E433:')
217 call assert_equal([17, 'a18', '', {}], g:TagFunc1Args) 217 call assert_equal([17, 'a18', '', {}], g:TagFunc1Args)
218 bw! 218 bw!
219 219
220 #" Set 'tagfunc' to a string(lambda expression) 220 #" Set 'tagfunc' to a string(lambda expression)
221 LET &tagfunc = 'LSTART a, b, c LMIDDLE TagFunc1(18, a, b, c) LEND' 221 LET &tagfunc = 'LSTART a, b, c LMIDDLE g:TagFunc1(18, a, b, c) LEND'
222 new 222 new
223 LET g:TagFunc1Args = [] 223 LET g:TagFunc1Args = []
224 call assert_fails('tag a18', 'E433:') 224 call assert_fails('tag a18', 'E433:')
225 call assert_equal([18, 'a18', '', {}], g:TagFunc1Args) 225 call assert_equal([18, 'a18', '', {}], g:TagFunc1Args)
226 bw! 226 bw!
227 227
228 #" Set 'tagfunc' to a variable with a lambda expression 228 #" Set 'tagfunc' to a variable with a lambda expression
229 VAR Lambda = LSTART a, b, c LMIDDLE TagFunc1(19, a, b, c) LEND 229 VAR Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(19, a, b, c) LEND
230 LET &tagfunc = Lambda 230 LET &tagfunc = Lambda
231 new 231 new
232 LET g:TagFunc1Args = [] 232 LET g:TagFunc1Args = []
233 call assert_fails("tag a19", "E433:") 233 call assert_fails("tag a19", "E433:")
234 call assert_equal([19, 'a19', '', {}], g:TagFunc1Args) 234 call assert_equal([19, 'a19', '', {}], g:TagFunc1Args)
235 bw! 235 bw!
236 236
237 #" Set 'tagfunc' to a string(variable with a lambda expression) 237 #" Set 'tagfunc' to a string(variable with a lambda expression)
238 LET Lambda = LSTART a, b, c LMIDDLE TagFunc1(20, a, b, c) LEND 238 LET Lambda = LSTART a, b, c LMIDDLE g:TagFunc1(20, a, b, c) LEND
239 LET &tagfunc = string(Lambda) 239 LET &tagfunc = string(Lambda)
240 new 240 new
241 LET g:TagFunc1Args = [] 241 LET g:TagFunc1Args = []
242 call assert_fails("tag a19", "E433:") 242 call assert_fails("tag a19", "E433:")
243 call assert_equal([20, 'a19', '', {}], g:TagFunc1Args) 243 call assert_equal([20, 'a19', '', {}], g:TagFunc1Args)
263 call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:') 263 call assert_fails("LET &tagfunc = function('NonExistingFunc')", 'E700:')
264 call assert_fails("tag axb123", 'E426:') 264 call assert_fails("tag axb123", 'E426:')
265 call assert_equal([], g:TagFunc2Args) 265 call assert_equal([], g:TagFunc2Args)
266 bw! 266 bw!
267 END 267 END
268 call CheckLegacyAndVim9Success(lines) 268 call v9.CheckLegacyAndVim9Success(lines)
269 269
270 " Test for using a script-local function name 270 " Test for using a script-local function name
271 func s:TagFunc3(pat, flags, info) 271 func s:TagFunc3(pat, flags, info)
272 let g:TagFunc3Args = [a:pat, a:flags, a:info] 272 let g:TagFunc3Args = [a:pat, a:flags, a:info]
273 return v:null 273 return v:null
378 g:LocalTagFuncArgs = [] 378 g:LocalTagFuncArgs = []
379 assert_fails('tag a12', 'E433:') 379 assert_fails('tag a12', 'E433:')
380 assert_equal(['a12', '', {}], g:LocalTagFuncArgs) 380 assert_equal(['a12', '', {}], g:LocalTagFuncArgs)
381 bw! 381 bw!
382 END 382 END
383 call CheckScriptSuccess(lines) 383 call v9.CheckScriptSuccess(lines)
384 384
385 " cleanup 385 " cleanup
386 delfunc TagFunc1 386 delfunc TagFunc1
387 delfunc TagFunc2 387 delfunc TagFunc2
388 set tagfunc& 388 set tagfunc&