comparison src/testdir/test_vim9_script.vim @ 24460:f0a3adf16f01 v8.2.2770

patch 8.2.2770: Vim9: type of loop variable is not used Commit: https://github.com/vim/vim/commit/fe090eb58fad1aaf83267d0b4ace9f024a5ba2bc Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 15 21:48:32 2021 +0200 patch 8.2.2770: Vim9: type of loop variable is not used Problem: Vim9: type of loop variable is not used. Solution: Parse and check the variable type. (closes https://github.com/vim/vim/issues/8107)
author Bram Moolenaar <Bram@vim.org>
date Thu, 15 Apr 2021 22:00:05 +0200
parents f388a033e568
children e5db23a8ad98
comparison
equal deleted inserted replaced
24459:6a4b9b9acb7d 24460:f0a3adf16f01
2341 for n: number in [1, 2, 3] 2341 for n: number in [1, 2, 3]
2342 total += n 2342 total += n
2343 endfor 2343 endfor
2344 assert_equal(6, total) 2344 assert_equal(6, total)
2345 2345
2346 var chars = ''
2347 for s: string in 'foobar'
2348 chars ..= s
2349 endfor
2350 assert_equal('foobar', chars)
2351
2346 # unpack with type 2352 # unpack with type
2347 var res = '' 2353 var res = ''
2348 for [n: number, s: string] in [[1, 'a'], [2, 'b']] 2354 for [n: number, s: string] in [[1, 'a'], [2, 'b']]
2349 res ..= n .. s 2355 res ..= n .. s
2350 endfor 2356 endfor
2406 for e in d 2412 for e in d
2407 e = {a: 0, b: ''} 2413 e = {a: 0, b: ''}
2408 endfor 2414 endfor
2409 END 2415 END
2410 CheckDefAndScriptFailure2(lines, 'E1018:', 'E46:', 3) 2416 CheckDefAndScriptFailure2(lines, 'E1018:', 'E46:', 3)
2417
2418 lines =<< trim END
2419 for nr: number in ['foo']
2420 endfor
2421 END
2422 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
2411 enddef 2423 enddef
2412 2424
2413 def Test_for_loop_script_var() 2425 def Test_for_loop_script_var()
2414 # cannot use s:var in a :def function 2426 # cannot use s:var in a :def function
2415 CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1101:') 2427 CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1101:')